{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/XXXX/miniconda3/envs/pytorch/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
      "  return f(*args, **kwds)\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from datetime import datetime\n",
    "from datetime import timedelta\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "file_path=\"~/Documents/Data/Full_MIMIC/\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ROW_ID</th>\n",
       "      <th>SUBJECT_ID</th>\n",
       "      <th>HADM_ID</th>\n",
       "      <th>ADMITTIME</th>\n",
       "      <th>DISCHTIME</th>\n",
       "      <th>DEATHTIME</th>\n",
       "      <th>ADMISSION_TYPE</th>\n",
       "      <th>ADMISSION_LOCATION</th>\n",
       "      <th>DISCHARGE_LOCATION</th>\n",
       "      <th>INSURANCE</th>\n",
       "      <th>LANGUAGE</th>\n",
       "      <th>RELIGION</th>\n",
       "      <th>MARITAL_STATUS</th>\n",
       "      <th>ETHNICITY</th>\n",
       "      <th>EDREGTIME</th>\n",
       "      <th>EDOUTTIME</th>\n",
       "      <th>DIAGNOSIS</th>\n",
       "      <th>HOSPITAL_EXPIRE_FLAG</th>\n",
       "      <th>HAS_CHARTEVENTS_DATA</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>21</td>\n",
       "      <td>22</td>\n",
       "      <td>165315</td>\n",
       "      <td>2196-04-09 12:26:00</td>\n",
       "      <td>2196-04-10 15:54:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>EMERGENCY</td>\n",
       "      <td>EMERGENCY ROOM ADMIT</td>\n",
       "      <td>DISC-TRAN CANCER/CHLDRN H</td>\n",
       "      <td>Private</td>\n",
       "      <td>NaN</td>\n",
       "      <td>UNOBTAINABLE</td>\n",
       "      <td>MARRIED</td>\n",
       "      <td>WHITE</td>\n",
       "      <td>2196-04-09 10:06:00</td>\n",
       "      <td>2196-04-09 13:24:00</td>\n",
       "      <td>BENZODIAZEPINE OVERDOSE</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>22</td>\n",
       "      <td>23</td>\n",
       "      <td>152223</td>\n",
       "      <td>2153-09-03 07:15:00</td>\n",
       "      <td>2153-09-08 19:10:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>ELECTIVE</td>\n",
       "      <td>PHYS REFERRAL/NORMAL DELI</td>\n",
       "      <td>HOME HEALTH CARE</td>\n",
       "      <td>Medicare</td>\n",
       "      <td>NaN</td>\n",
       "      <td>CATHOLIC</td>\n",
       "      <td>MARRIED</td>\n",
       "      <td>WHITE</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>CORONARY ARTERY DISEASE\\CORONARY ARTERY BYPASS...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>124321</td>\n",
       "      <td>2157-10-18 19:34:00</td>\n",
       "      <td>2157-10-25 14:00:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>EMERGENCY</td>\n",
       "      <td>TRANSFER FROM HOSP/EXTRAM</td>\n",
       "      <td>HOME HEALTH CARE</td>\n",
       "      <td>Medicare</td>\n",
       "      <td>ENGL</td>\n",
       "      <td>CATHOLIC</td>\n",
       "      <td>MARRIED</td>\n",
       "      <td>WHITE</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>BRAIN MASS</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>24</td>\n",
       "      <td>24</td>\n",
       "      <td>161859</td>\n",
       "      <td>2139-06-06 16:14:00</td>\n",
       "      <td>2139-06-09 12:48:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>EMERGENCY</td>\n",
       "      <td>TRANSFER FROM HOSP/EXTRAM</td>\n",
       "      <td>HOME</td>\n",
       "      <td>Private</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PROTESTANT QUAKER</td>\n",
       "      <td>SINGLE</td>\n",
       "      <td>WHITE</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>INTERIOR MYOCARDIAL INFARCTION</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>25</td>\n",
       "      <td>25</td>\n",
       "      <td>129635</td>\n",
       "      <td>2160-11-02 02:06:00</td>\n",
       "      <td>2160-11-05 14:55:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>EMERGENCY</td>\n",
       "      <td>EMERGENCY ROOM ADMIT</td>\n",
       "      <td>HOME</td>\n",
       "      <td>Private</td>\n",
       "      <td>NaN</td>\n",
       "      <td>UNOBTAINABLE</td>\n",
       "      <td>MARRIED</td>\n",
       "      <td>WHITE</td>\n",
       "      <td>2160-11-02 01:01:00</td>\n",
       "      <td>2160-11-02 04:27:00</td>\n",
       "      <td>ACUTE CORONARY SYNDROME</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ROW_ID  SUBJECT_ID  HADM_ID            ADMITTIME            DISCHTIME  \\\n",
       "0      21          22   165315  2196-04-09 12:26:00  2196-04-10 15:54:00   \n",
       "1      22          23   152223  2153-09-03 07:15:00  2153-09-08 19:10:00   \n",
       "2      23          23   124321  2157-10-18 19:34:00  2157-10-25 14:00:00   \n",
       "3      24          24   161859  2139-06-06 16:14:00  2139-06-09 12:48:00   \n",
       "4      25          25   129635  2160-11-02 02:06:00  2160-11-05 14:55:00   \n",
       "\n",
       "  DEATHTIME ADMISSION_TYPE         ADMISSION_LOCATION  \\\n",
       "0       NaN      EMERGENCY       EMERGENCY ROOM ADMIT   \n",
       "1       NaN       ELECTIVE  PHYS REFERRAL/NORMAL DELI   \n",
       "2       NaN      EMERGENCY  TRANSFER FROM HOSP/EXTRAM   \n",
       "3       NaN      EMERGENCY  TRANSFER FROM HOSP/EXTRAM   \n",
       "4       NaN      EMERGENCY       EMERGENCY ROOM ADMIT   \n",
       "\n",
       "          DISCHARGE_LOCATION INSURANCE LANGUAGE           RELIGION  \\\n",
       "0  DISC-TRAN CANCER/CHLDRN H   Private      NaN       UNOBTAINABLE   \n",
       "1           HOME HEALTH CARE  Medicare      NaN           CATHOLIC   \n",
       "2           HOME HEALTH CARE  Medicare     ENGL           CATHOLIC   \n",
       "3                       HOME   Private      NaN  PROTESTANT QUAKER   \n",
       "4                       HOME   Private      NaN       UNOBTAINABLE   \n",
       "\n",
       "  MARITAL_STATUS ETHNICITY            EDREGTIME            EDOUTTIME  \\\n",
       "0        MARRIED     WHITE  2196-04-09 10:06:00  2196-04-09 13:24:00   \n",
       "1        MARRIED     WHITE                  NaN                  NaN   \n",
       "2        MARRIED     WHITE                  NaN                  NaN   \n",
       "3         SINGLE     WHITE                  NaN                  NaN   \n",
       "4        MARRIED     WHITE  2160-11-02 01:01:00  2160-11-02 04:27:00   \n",
       "\n",
       "                                           DIAGNOSIS  HOSPITAL_EXPIRE_FLAG  \\\n",
       "0                            BENZODIAZEPINE OVERDOSE                     0   \n",
       "1  CORONARY ARTERY DISEASE\\CORONARY ARTERY BYPASS...                     0   \n",
       "2                                         BRAIN MASS                     0   \n",
       "3                     INTERIOR MYOCARDIAL INFARCTION                     0   \n",
       "4                            ACUTE CORONARY SYNDROME                     0   \n",
       "\n",
       "   HAS_CHARTEVENTS_DATA  \n",
       "0                     1  \n",
       "1                     1  \n",
       "2                     1  \n",
       "3                     1  \n",
       "4                     1  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adm=pd.read_csv(file_path+\"ADMISSIONS.csv\")\n",
    "adm.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Load the patients data base and add the Date of birth to the admission dataset.\n",
    "patients_df=pd.read_csv(file_path+\"PATIENTS.csv\")\n",
    "patients_df[\"DOBTIME\"]=pd.to_datetime(patients_df[\"DOB\"], format='%Y-%m-%d')\n",
    "patients_df[[\"SUBJECT_ID\",\"DOBTIME\"]].head()\n",
    "adm_dob=pd.merge(patients_df[[\"SUBJECT_ID\",\"DOBTIME\"]],adm,on=\"SUBJECT_ID\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAD8CAYAAACcjGjIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAFbxJREFUeJzt3X+sX3Wd5/Hna1pQsq7TIldD2u6WnWlmrGateheauH+w6EJBM2USSUpmpTFs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JwLBz+GY2ZJdiQ5luSJvtqFSfYnOdxel4+yj6OWZFWSB5IcSnIwycdb3fN0iiRvTPJQkp+0c/WZVr8kyYPtXH2jDTJ53UuyJMkjSb7dlhf1eTqnwqHvYziuBtYC1ydZO9peLSp3ARtOqW0D7quqNcB9bfn17ATwyap6O7Ae2Nr+DXmeul4GrqiqdwHrgA1J1gNfBG5r5+p54MYR9nEx+ThwqG95UZ+ncyoc6PsYjqr6NXDyYzgEVNX3geOnlDcCO9v8TuDas9qpRaaqjlbVj9v8S/T+M6/A89RRPb9si+e1qYArgHta3XMFJFkJfBD4m7YcFvl5OtfCYdDHcKwYUV9eK95WVUeh94sReOuI+7NoJFkNvBt4EM/TQO1WyaPAMWA/8I/AC1V1ojXx/2DPl4G/AH7Tlt/CIj9P51o4ZEDN4ViasyRvAr4JfKKqfjHq/ixWVfVKVa2j96kGlwJvH9Ts7PZqcUnyIeBYVT3cXx7QdFGdp0XzPoczZKiP4dD/57kkF1fV0SQX0/sL8HUtyXn0guFrVfWtVvY8nUZVvZDke/Se0yxLsrT9Vez/QXgf8CdJrgHeCLyZ3pXEoj5P59qVgx/DMXd7gM1tfjNw7wj7MnLtXvCdwKGq+lLfKs/TKZKMJVnW5i8APkDvGc0DwIdbs9f9uaqqm6tqZVWtpvc76f6q+jMW+Xk6594E19L5y/z2YzhuHXGXFo0kXwcup/eJkM8BtwD/HdgN/AvgZ8B1VXXqQ+vXjST/FvhfwOP89v7wp+k9d/A89Unyr+k9SF1C7w/N3VX12ST/it5gkAuBR4D/UFUvj66ni0eSy4H/UlUfWuzn6ZwLB0nSwp1rt5UkSWeA4SBJ6jAcJEkdhoMkqcNwkCR1GA6SpA7DQZLUYThIkjr+H1qg8ve50naQAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10dcad908>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients with specific number of admissions : \n",
      " 1     38983\n",
      "2      5160\n",
      "3      1342\n",
      "4       508\n",
      "5       246\n",
      "6       113\n",
      "7        51\n",
      "8        31\n",
      "9        26\n",
      "10       14\n",
      "11       13\n",
      "12        8\n",
      "13        5\n",
      "14        4\n",
      "17        3\n",
      "16        2\n",
      "34        2\n",
      "24        1\n",
      "42        1\n",
      "15        1\n",
      "19        1\n",
      "20        1\n",
      "21        1\n",
      "22        1\n",
      "23        1\n",
      "31        1\n",
      "Name: HADM_ID, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "#Number of admissions by patient\n",
    "df=adm.groupby(\"SUBJECT_ID\")[\"HADM_ID\"].nunique()\n",
    "plt.hist(df,bins=100)\n",
    "plt.show()\n",
    "print(\"Number of patients with specific number of admissions : \\n\",df.value_counts())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As the majortity of patients only present a single admission, we filter out all the patients with more than 1 admission"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients remaining in the dataframe: \n",
      "38983\n"
     ]
    }
   ],
   "source": [
    "subj_ids=list(df[df==1].index) #index of patients with only one visit.\n",
    "adm_1=adm_dob.loc[adm_dob[\"SUBJECT_ID\"].isin(subj_ids)] #filter out the patients with more than one visit\n",
    "print(\"Number of patients remaining in the dataframe: \")\n",
    "print(len(adm_1.index))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADytJREFUeJzt3X+o3Xd9x/Hny0bdmMO29iolCbvdDMP6x2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y7XR6PVlJ1ie5P8nBJAeSvK/VZ25bWrUBMHTbieuAy4F3Jrl8ur2aKX9WVVcMXYq2C7ivqjYA97X53nwG2HxKbalxuQ7Y0B47gNsn1Mdp+wwvHSOA29r2dEU7z0f7edsKvLG95lPt53K1OwF8oKreAGwCdraxmLltadUGAEO3naiq/wVO3nZCi9sC7GnTe4AbptiXqaiqbwLHTykvNS5bgM/WwLeAC5NcOpmeTs8SY7SULcDeqnq+qn4EHGbwc7mqVdXTVfXtNv1z4CCDuyDM3La0mgNgsdtOrJ1SX2ZNAf+e5OH2zWuA11XV0zDYgIHXTq13s2WpcXH7erH3tsMXu4cOH3Y/RknmgTcBDzCD29JqDoAsUvOSp4G3VNWVDHY9dyb5k2l36Dzk9vUbtwN/AFwBPA38c6t3PUZJXgV8GXh/Vf3sdE0XqU1knFZzAIy87USvquqp9nwU+DcGu+XPnNztbM9Hp9fDmbLUuLh9NVX1TFW9UFW/Av6V3xzm6XaMkrycwS//z1fVV1p55ral1RwA3nZiEUl+J8nvnpwGrgG+z2BstrVm24C7p9PDmbPUuOwD3t2u4NgEPHdy9743pxyvfjuD7QkGY7Q1ySuTXMbgJOeDk+7fpCUJcCdwsKo+NrRo9ralqlq1D+B64D+BHwAfnHZ/ZuEB/D7w3fY4cHJcgNcwuDLhUHu+eNp9ncLYfIHBIYz/Y/BX2falxoXBbvsn27b1PWDjtPs/xTH6XBuDRxn8Mrt0qP0H2xg9Dlw37f5PaIz+mMEhnEeBR9rj+lnclvwmsCR1ajUfApIknYYBIEmdMgAkqVMGgCR1ygCQpE4ZAJLUKQNAkjplAEhSp/4f1agOGlkbMzQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10dcadcc0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients with specific duration of admissions in days : \n",
      " 4      4333\n",
      "2      4216\n",
      "3      3478\n",
      "5      3119\n",
      "6      2739\n",
      "1      2424\n",
      "7      2346\n",
      "8      1948\n",
      "9      1598\n",
      "0      1476\n",
      "10     1320\n",
      "11     1088\n",
      "12      899\n",
      "13      835\n",
      "14      659\n",
      "15      607\n",
      "16      527\n",
      "17      490\n",
      "18      409\n",
      "20      356\n",
      "19      321\n",
      "21      273\n",
      "22      250\n",
      "23      221\n",
      "24      217\n",
      "25      185\n",
      "26      166\n",
      "27      164\n",
      "28      160\n",
      "29      132\n",
      "       ... \n",
      "148       2\n",
      "117       2\n",
      "118       2\n",
      "171       2\n",
      "119       2\n",
      "127       2\n",
      "105       1\n",
      "136       1\n",
      "122       1\n",
      "133       1\n",
      "115       1\n",
      "128       1\n",
      "103       1\n",
      "206       1\n",
      "142       1\n",
      "135       1\n",
      "141       1\n",
      "161       1\n",
      "109       1\n",
      "167       1\n",
      "181       1\n",
      "155       1\n",
      "164       1\n",
      "150       1\n",
      "166       1\n",
      "121       1\n",
      "151       1\n",
      "163       1\n",
      "169       1\n",
      "202       1\n",
      "Name: ELAPSED_DAYS, Length: 156, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "#We now add a new column with the duration of each stay.\n",
    "adm_1=adm_1.copy()\n",
    "adm_1['ADMITTIME']=pd.to_datetime(adm_1[\"ADMITTIME\"], format='%Y-%m-%d %H:%M:%S')\n",
    "adm_1['DISCHTIME']=pd.to_datetime(adm_1[\"DISCHTIME\"], format='%Y-%m-%d %H:%M:%S')\n",
    "\n",
    "adm_1[\"ELAPSED_TIME\"]=adm_1[\"DISCHTIME\"]-adm_1[\"ADMITTIME\"]\n",
    "adm_1.head()\n",
    "adm_1[\"ELAPSED_DAYS\"]=adm_1[\"ELAPSED_TIME\"].dt.days #Elapsed time in days in ICU\n",
    "plt.hist(adm_1[\"ELAPSED_DAYS\"],bins=200)\n",
    "plt.show()\n",
    "print(\"Number of patients with specific duration of admissions in days : \\n\",adm_1[\"ELAPSED_DAYS\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "met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     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Let's now report the death rate in function of the duration stay in ICU.\n",
    "adm_1[\"DEATHTAG\"]=0\n",
    "adm_1.loc[adm_1.DEATHTIME.notnull(),\"DEATHTAG\"]=1\n",
    "\n",
    "df_deaths_per_duration=adm_1.groupby(\"ELAPSED_DAYS\")[\"DEATHTAG\"].sum()\n",
    "df_patients_per_duration=adm_1.groupby(\"ELAPSED_DAYS\")[\"SUBJECT_ID\"].nunique()\n",
    "df_death_ratio_per_duration=df_deaths_per_duration/df_patients_per_duration\n",
    "plt.plot(df_death_ratio_per_duration)\n",
    "plt.title(\"Death Ratio per ICU stay duration\")\n",
    "plt.xlabel(\"Duration in days\")\n",
    "plt.ylabel(\"Death rate (Number of deaths/Nunber of patients)\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given the results above, we select patients with a least 48 hours in the ICU and with less than 30 days stay."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients remaining in the dataframe: \n",
      "28840\n"
     ]
    }
   ],
   "source": [
    "adm_2=adm_1.loc[(adm_1[\"ELAPSED_DAYS\"]<30) & (adm_1[\"ELAPSED_DAYS\"]>2)]\n",
    "print(\"Number of patients remaining in the dataframe: \")\n",
    "print(len(adm_2.index))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We remove the patients who are younger than 15 at admission time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients remaining in the dataframe: \n",
      "23495\n"
     ]
    }
   ],
   "source": [
    "adm_2_15=adm_2.loc[((adm_2[\"ADMITTIME\"]-adm_2[\"DOBTIME\"]).dt.days/365)>15].copy()\n",
    "print(\"Number of patients remaining in the dataframe: \")\n",
    "print(len(adm_2_15.index))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We remove the admissions with no chart events data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients remaining in the dataframe: \n",
      "23465\n"
     ]
    }
   ],
   "source": [
    "adm_2_15_chart=adm_2_15.loc[adm_2_15[\"HAS_CHARTEVENTS_DATA\"]==1].copy()\n",
    "print(\"Number of patients remaining in the dataframe: \")\n",
    "print(len(adm_2_15_chart.index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ADMISSION_TYPE\n",
       "ELECTIVE      4577\n",
       "EMERGENCY    18187\n",
       "URGENT         701\n",
       "Name: SUBJECT_ID, dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#We now investigate the admission_type\n",
    "df_type=adm_2_15_chart.groupby(\"ADMISSION_TYPE\")[\"SUBJECT_ID\"].count()\n",
    "df_type"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We remove the newborns as they are specific"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients remaining in the dataframe: \n",
      "23465\n"
     ]
    }
   ],
   "source": [
    "adm_3=adm_2_15_chart.loc[adm_2_15_chart[\"ADMISSION_TYPE\"]!=\"NEWBORN\"]\n",
    "print(\"Number of patients remaining in the dataframe: \")\n",
    "print(adm_3[\"SUBJECT_ID\"].nunique())\n",
    "\n",
    "adm_3.to_csv(file_path+\"./Admissions_processed.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## INPUTS EVENTS DATA\n",
    "\n",
    "We now consider the inputevents dataset. We select only the patients in the metavision system and with the same criteria as above."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   SUBJECT_ID  HADM_ID            STARTTIME              ENDTIME  ITEMID  \\\n",
      "0       27063   139787  2133-02-05 06:29:00  2133-02-05 08:45:00  225166   \n",
      "1       27063   139787  2133-02-05 05:34:00  2133-02-05 06:30:00  225944   \n",
      "2       27063   139787  2133-02-05 05:34:00  2133-02-05 06:30:00  225166   \n",
      "3       27063   139787  2133-02-03 12:00:00  2133-02-03 12:01:00  225893   \n",
      "4       27063   139787  2133-02-03 12:00:00  2133-02-03 12:01:00  220949   \n",
      "\n",
      "       AMOUNT AMOUNTUOM       RATE  RATEUOM  PATIENTWEIGHT  \\\n",
      "0    6.774532       mEq        NaN      NaN           83.2   \n",
      "1   28.132997        ml  30.142497  mL/hour           83.2   \n",
      "2    2.813300       mEq        NaN      NaN           83.2   \n",
      "3    1.000000      dose        NaN      NaN           83.2   \n",
      "4  100.000000        ml        NaN      NaN           83.2   \n",
      "\n",
      "  ORDERCATEGORYDESCRIPTION  \n",
      "0            Continuous IV  \n",
      "1            Continuous IV  \n",
      "2            Continuous IV  \n",
      "3                Drug Push  \n",
      "4                Drug Push  \n",
      "Number of patients remaining in the database: \n",
      "10100\n"
     ]
    }
   ],
   "source": [
    "inputs=pd.read_csv(file_path+\"INPUTEVENTS_MV.csv\")\n",
    "#Restrict the dataset to the previously selected admission ids only.\n",
    "adm_ids=list(adm_3[\"HADM_ID\"])\n",
    "inputs=inputs.loc[inputs[\"HADM_ID\"].isin(adm_ids)]\n",
    "\n",
    "#Inputs_small only contains the columns of interest.\n",
    "inputs_small=inputs[[\"SUBJECT_ID\",\"HADM_ID\",\"STARTTIME\",\"ENDTIME\",\"ITEMID\",\"AMOUNT\",\"AMOUNTUOM\",\"RATE\",\"RATEUOM\",\"PATIENTWEIGHT\",\"ORDERCATEGORYDESCRIPTION\"]]\n",
    "print(inputs_small.head())\n",
    "\n",
    "print(\"Number of patients remaining in the database: \")\n",
    "print(inputs_small[\"SUBJECT_ID\"].nunique())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We load the D_ITEMS dataframe which contains the name of the ITEMID. And we merge both tables together."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients remaining in the database: \n",
      "10100\n"
     ]
    }
   ],
   "source": [
    "#item_id \n",
    "item_id=pd.read_csv(file_path+\"D_ITEMS.csv\")\n",
    "item_id_1=item_id[[\"ITEMID\",\"LABEL\"]]\n",
    "item_id_1.head()\n",
    "\n",
    "#We merge the name of the item administrated.\n",
    "inputs_small_2=pd.merge(inputs_small,item_id_1,on=\"ITEMID\")\n",
    "inputs_small_2.head()\n",
    "print(\"Number of patients remaining in the database: \")\n",
    "print(inputs_small_2[\"SUBJECT_ID\"].nunique())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients remaining in the database: \n",
      "10099\n"
     ]
    }
   ],
   "source": [
    "#For each item, evaluate the number of patients who have been given this item.\n",
    "pat_for_item=inputs_small_2.groupby(\"LABEL\")[\"SUBJECT_ID\"].nunique()\n",
    "#Order by occurence and take the 33 best (the ones with the most patients)\n",
    "frequent_labels=pat_for_item.sort_values(ascending=False)[:50]\n",
    "\n",
    "#Select only the time series with high occurence.\n",
    "inputs_small_3=inputs_small_2.loc[inputs_small_2[\"LABEL\"].isin(list(frequent_labels.index))].copy()\n",
    "\n",
    "print(\"Number of patients remaining in the database: \")\n",
    "print(inputs_small_3[\"SUBJECT_ID\"].nunique())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Only select specific labels for the inputs.\n",
    "#list of retained inputs :\n",
    "retained_list=[\"Albumin 5%\",\"Dextrose 5%\",\"Lorazepam (Ativan)\",\"Calcium Gluconate\",\"Midazolam (Versed)\",\"Phenylephrine\",\"Furosemide (Lasix)\",\"Hydralazine\",\"Norepinephrine\",\"Magnesium Sulfate\",\"Nitroglycerin\",\"Insulin - Glargine\",\"Insulin - Humalog\",\"Insulin - Regular\",\"Heparin Sodium\",\"Morphine Sulfate\",\"Potassium Chloride\",\"Packed Red Blood Cells\",\"Gastric Meds\",\"D5 1/2NS\",\"LR\",\"K Phos\",\"Solution\",\"Sterile Water\",\"Metoprolol\",\"Piggyback\",\"OR Crystalloid Intake\",\"OR Cell Saver Intake\",\"PO Intake\",\"GT Flush\",\"KCL (Bolus)\",\"Magnesium Sulfate (Bolus)\"]\n",
    "#missing :Fresh Frozen Plasma\n",
    "inputs_small_3=inputs_small_3.loc[inputs_small_3[\"LABEL\"].isin(retained_list)].copy()\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cleaning of the input data\n",
    "\n",
    "### Units Cleaning\n",
    "\n",
    "#### 1) Amounts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LABEL                      AMOUNTUOM\n",
       "Albumin 5%                 ml             4050\n",
       "Calcium Gluconate          grams         12193\n",
       "D5 1/2NS                   ml             8322\n",
       "Dextrose 5%                ml           191961\n",
       "Furosemide (Lasix)         mg            21904\n",
       "GT Flush                   ml            26003\n",
       "Gastric Meds               ml            38580\n",
       "Heparin Sodium             units         14522\n",
       "Hydralazine                mg             7310\n",
       "Insulin - Glargine         units          4127\n",
       "Insulin - Humalog          units         12671\n",
       "Insulin - Regular          units         65047\n",
       "K Phos                     mmol           3002\n",
       "KCL (Bolus)                ml            21302\n",
       "LR                         ml            29414\n",
       "Lorazepam (Ativan)         mg             9660\n",
       "Magnesium Sulfate          grams         13120\n",
       "                           mg                1\n",
       "Magnesium Sulfate (Bolus)  ml             9283\n",
       "Metoprolol                 mg            15485\n",
       "                           mcg               1\n",
       "Midazolam (Versed)         mg            33687\n",
       "Morphine Sulfate           mg            22765\n",
       "Nitroglycerin              mg            21664\n",
       "Norepinephrine             mg            34950\n",
       "OR Cell Saver Intake       ml             1509\n",
       "OR Crystalloid Intake      ml             4312\n",
       "PO Intake                  ml            63597\n",
       "Packed Red Blood Cells     ml            10456\n",
       "Phenylephrine              mg            46652\n",
       "Piggyback                  ml            17939\n",
       "Potassium Chloride         mEq           41829\n",
       "Solution                   ml           133523\n",
       "Sterile Water              ml            11647\n",
       "Name: AMOUNTUOM, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Verification that all input labels have the same amounts units.\n",
    "inputs_small_3.groupby(\"LABEL\")[\"AMOUNTUOM\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LABEL                      AMOUNTUOM\n",
       "Albumin 5%                 ml             4050\n",
       "Calcium Gluconate          grams         12193\n",
       "D5 1/2NS                   ml             8322\n",
       "Dextrose 5%                ml           191961\n",
       "Furosemide (Lasix)         mg            21904\n",
       "GT Flush                   ml            26003\n",
       "Gastric Meds               ml            38580\n",
       "Heparin Sodium             units         14522\n",
       "Hydralazine                mg             7310\n",
       "Insulin - Glargine         units          4127\n",
       "Insulin - Humalog          units         12671\n",
       "Insulin - Regular          units         65047\n",
       "K Phos                     mmol           3002\n",
       "KCL (Bolus)                ml            21302\n",
       "LR                         ml            29414\n",
       "Lorazepam (Ativan)         mg             9660\n",
       "Magnesium Sulfate          grams         13120\n",
       "Magnesium Sulfate (Bolus)  ml             9283\n",
       "Metoprolol                 mg            15485\n",
       "Midazolam (Versed)         mg            33687\n",
       "Morphine Sulfate           mg            22765\n",
       "Nitroglycerin              mg            21664\n",
       "Norepinephrine             mg            34950\n",
       "OR Cell Saver Intake       ml             1509\n",
       "OR Crystalloid Intake      ml             4312\n",
       "PO Intake                  ml            63597\n",
       "Packed Red Blood Cells     ml            10456\n",
       "Phenylephrine              mg            46652\n",
       "Piggyback                  ml            17939\n",
       "Potassium Chloride         mEq           41829\n",
       "Solution                   ml           133523\n",
       "Sterile Water              ml            11647\n",
       "Name: AMOUNTUOM, dtype: int64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##### Cleaning the Cefazolin (remove the ones that are not in dose unit)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"ITEMID\"]==225850) & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Cefepime (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefepime\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Ceftriaxone (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Ceftriaxone\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Ciprofloxacin (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Ciprofloxacin\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Famotidine (Pepcid) (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Famotidine (Pepcid)\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Fentanyl (Concentrate) (remove the non mg)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"mg\")].index).copy()\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNTUOM\"]==\"mg\"),\"AMOUNT\"]*=1000\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNTUOM\"]==\"mg\"),\"AMOUNTUOM\"]=\"mcg\"\n",
    "#Cleaning the Heparin Sodium (Prophylaxis) (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Heparin Sodium (Prophylaxis)\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Hydromorphone (Dilaudid) (remove the non mg)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Hydromorphone (Dilaudid)\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"mg\")].index).copy()\n",
    "#Cleaning the Magnesium Sulfate (remove the non grams)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Magnesium Sulfate\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"grams\")].index).copy()\n",
    "#Cleaning the Propofol (remove the non mg)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Propofol\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"mg\")].index).copy()\n",
    "#Cleaning the Metoprolol (remove the non mg)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Metoprolol\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"mg\")].index).copy()\n",
    "#Cleaning the Piperacillin/Tazobactam (Zosyn) (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Piperacillin/Tazobactam (Zosyn)\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Metronidazole (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Metronidazole\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Ranitidine (Prophylaxis)(remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Ranitidine (Prophylaxis)\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Vancomycin (remove the non dose)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Vancomycin\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "#Cleaning the Fentanyl. Put the mg to mcg \n",
    "inputs_small_3.loc[(inputs_small_3[\"ITEMID\"]==221744) & (inputs_small_3[\"AMOUNTUOM\"]==\"mg\"),\"AMOUNT\"]*=1000\n",
    "inputs_small_3.loc[(inputs_small_3[\"ITEMID\"]==221744) & (inputs_small_3[\"AMOUNTUOM\"]==\"mg\"),\"AMOUNTUOM\"]=\"mcg\"\n",
    "#Cleaning of the Pantoprazole (Protonix)\n",
    "    #divide in two (drug shot or continuous treatment and create a new item id for the continuous version)\n",
    "inputs_small_3.loc[(inputs_small_3[\"ITEMID\"]==225910) & (inputs_small_3[\"ORDERCATEGORYDESCRIPTION\"]==\"Continuous Med\"),\"LABEL\"]=\"Pantoprazole (Protonix) Continuous\"\n",
    "inputs_small_3.loc[(inputs_small_3[\"ITEMID\"]==225910) & (inputs_small_3[\"ORDERCATEGORYDESCRIPTION\"]==\"Continuous Med\"),\"ITEMID\"]=2217441\n",
    "#remove the non dose from the drug shot version\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Pantoprazole (Protonix)\") & (inputs_small_3[\"AMOUNTUOM\"]!=\"dose\")].index).copy()\n",
    "\n",
    "\n",
    "#Verification that all input labels have the same units.\n",
    "inputs_small_3.groupby(\"LABEL\")[\"AMOUNTUOM\"].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2) Rates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "#inputs_small_3.groupby(\"LABEL\")[\"RATEUOM\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LABEL                      RATEUOM   \n",
       "Albumin 5%                 mL/hour         4050\n",
       "D5 1/2NS                   mL/hour         8299\n",
       "Dextrose 5%                mL/hour       106902\n",
       "Furosemide (Lasix)         mg/hour         8843\n",
       "Heparin Sodium             units/hour     13413\n",
       "Hydralazine                mg/hour            2\n",
       "Insulin - Regular          units/hour     30520\n",
       "KCL (Bolus)                mL/hour        21302\n",
       "LR                         mL/hour        18543\n",
       "Lorazepam (Ativan)         mg/hour          104\n",
       "Magnesium Sulfate (Bolus)  mL/hour         9281\n",
       "Midazolam (Versed)         mg/hour        19412\n",
       "Morphine Sulfate           mg/hour         2004\n",
       "Nitroglycerin              mcg/kg/min     21664\n",
       "Norepinephrine             mcg/kg/min     34950\n",
       "Packed Red Blood Cells     mL/hour        10454\n",
       "Phenylephrine              mcg/kg/min     46652\n",
       "Piggyback                  mL/hour        17934\n",
       "Solution                   mL/hour       115980\n",
       "Sterile Water              mL/hour        11605\n",
       "Name: RATEUOM, dtype: int64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Cleaning of Dextrose 5%  (remove the non mL/hour)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Dextrose 5%\") & (inputs_small_3[\"RATEUOM\"]!=\"mL/hour\")].index).copy()\n",
    "#Cleaning of Magnesium Sulfate (Bolus)  (remove the non mL/hour)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Magnesium Sulfate (Bolus)\") & (inputs_small_3[\"RATEUOM\"]!=\"mL/hour\")].index).copy()\n",
    "#Cleaning of NaCl 0.9% (remove the non mL/hour)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"NaCl 0.9%\") & (inputs_small_3[\"RATEUOM\"]!=\"mL/hour\")].index).copy()\n",
    "#Cleaning of Piggyback (remove the non mL/hour)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Piggyback\") & (inputs_small_3[\"RATEUOM\"]!=\"mL/hour\")].index).copy()\n",
    "#Cleaning of Packed Red Bllod Cells (remove the non mL/hour)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Packed Red Blood Cells\") & (inputs_small_3[\"RATEUOM\"]!=\"mL/hour\")].index).copy()\n",
    "\n",
    "\n",
    "#Check if a single unit per drug\n",
    "inputs_small_3.groupby(\"LABEL\")[\"RATEUOM\"].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Check for outliers\n",
    "\n",
    "#### 1) In amounts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LABEL</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albumin 5%</th>\n",
       "      <td>4050.0</td>\n",
       "      <td>388.369612</td>\n",
       "      <td>166.110714</td>\n",
       "      <td>-149.999994</td>\n",
       "      <td>249.999990</td>\n",
       "      <td>499.999980</td>\n",
       "      <td>499.999980</td>\n",
       "      <td>5199.999792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Calcium Gluconate</th>\n",
       "      <td>12193.0</td>\n",
       "      <td>2.405072</td>\n",
       "      <td>3.491139</td>\n",
       "      <td>-0.933333</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>199.999998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D5 1/2NS</th>\n",
       "      <td>8322.0</td>\n",
       "      <td>636.180349</td>\n",
       "      <td>439.026112</td>\n",
       "      <td>-918.173907</td>\n",
       "      <td>201.666662</td>\n",
       "      <td>778.314861</td>\n",
       "      <td>999.999972</td>\n",
       "      <td>5999.999904</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dextrose 5%</th>\n",
       "      <td>106902.0</td>\n",
       "      <td>115.524221</td>\n",
       "      <td>191.605066</td>\n",
       "      <td>-5250.000000</td>\n",
       "      <td>6.577475</td>\n",
       "      <td>47.717591</td>\n",
       "      <td>153.333326</td>\n",
       "      <td>5000.000040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furosemide (Lasix)</th>\n",
       "      <td>21904.0</td>\n",
       "      <td>35.477109</td>\n",
       "      <td>44.378339</td>\n",
       "      <td>-120.000009</td>\n",
       "      <td>16.098319</td>\n",
       "      <td>20.000001</td>\n",
       "      <td>40.000003</td>\n",
       "      <td>2320.000200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GT Flush</th>\n",
       "      <td>26003.0</td>\n",
       "      <td>48.559512</td>\n",
       "      <td>63.428421</td>\n",
       "      <td>-3750.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>50.000000</td>\n",
       "      <td>2000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gastric Meds</th>\n",
       "      <td>38580.0</td>\n",
       "      <td>66.776721</td>\n",
       "      <td>1226.688211</td>\n",
       "      <td>-5400.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>60.000000</td>\n",
       "      <td>240120.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heparin Sodium</th>\n",
       "      <td>14522.0</td>\n",
       "      <td>9512.448239</td>\n",
       "      <td>9765.479419</td>\n",
       "      <td>-525000.000000</td>\n",
       "      <td>2157.095630</td>\n",
       "      <td>6858.147894</td>\n",
       "      <td>15555.605203</td>\n",
       "      <td>30640.000300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hydralazine</th>\n",
       "      <td>7310.0</td>\n",
       "      <td>11.922217</td>\n",
       "      <td>28.098023</td>\n",
       "      <td>-240.000012</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>2350.000100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Glargine</th>\n",
       "      <td>4127.0</td>\n",
       "      <td>23.442210</td>\n",
       "      <td>28.147084</td>\n",
       "      <td>-180.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>1515.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Humalog</th>\n",
       "      <td>12671.0</td>\n",
       "      <td>5.146176</td>\n",
       "      <td>10.454748</td>\n",
       "      <td>-30.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>900.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Regular</th>\n",
       "      <td>65047.0</td>\n",
       "      <td>7.845160</td>\n",
       "      <td>16.835473</td>\n",
       "      <td>-140.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>2499.999996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K Phos</th>\n",
       "      <td>3002.0</td>\n",
       "      <td>17.227494</td>\n",
       "      <td>7.996231</td>\n",
       "      <td>-2.279736</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>15.000001</td>\n",
       "      <td>16.753996</td>\n",
       "      <td>83.000005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KCL (Bolus)</th>\n",
       "      <td>21302.0</td>\n",
       "      <td>54.950031</td>\n",
       "      <td>33.179979</td>\n",
       "      <td>-23.333332</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>1000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LR</th>\n",
       "      <td>29414.0</td>\n",
       "      <td>655.032208</td>\n",
       "      <td>416.998701</td>\n",
       "      <td>-23000.000000</td>\n",
       "      <td>400.000000</td>\n",
       "      <td>664.782125</td>\n",
       "      <td>999.999984</td>\n",
       "      <td>16855.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lorazepam (Ativan)</th>\n",
       "      <td>9660.0</td>\n",
       "      <td>1.379741</td>\n",
       "      <td>3.178132</td>\n",
       "      <td>-120.000002</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>113.283334</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate</th>\n",
       "      <td>13120.0</td>\n",
       "      <td>2.048632</td>\n",
       "      <td>2.497431</td>\n",
       "      <td>-0.733333</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>249.999967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate (Bolus)</th>\n",
       "      <td>9281.0</td>\n",
       "      <td>49.575188</td>\n",
       "      <td>6.207162</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>249.999990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Metoprolol</th>\n",
       "      <td>15485.0</td>\n",
       "      <td>5.756933</td>\n",
       "      <td>4.152228</td>\n",
       "      <td>-180.000018</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>125.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Midazolam (Versed)</th>\n",
       "      <td>33687.0</td>\n",
       "      <td>17.852877</td>\n",
       "      <td>33.090963</td>\n",
       "      <td>-38.000002</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>16.989001</td>\n",
       "      <td>1710.134060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morphine Sulfate</th>\n",
       "      <td>22765.0</td>\n",
       "      <td>4.993317</td>\n",
       "      <td>19.674722</td>\n",
       "      <td>-60.000003</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.333333</td>\n",
       "      <td>1945.000100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nitroglycerin</th>\n",
       "      <td>21664.0</td>\n",
       "      <td>11.542607</td>\n",
       "      <td>22.662372</td>\n",
       "      <td>-19.000001</td>\n",
       "      <td>0.919592</td>\n",
       "      <td>2.716225</td>\n",
       "      <td>9.104737</td>\n",
       "      <td>200.000006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Norepinephrine</th>\n",
       "      <td>34950.0</td>\n",
       "      <td>1.794691</td>\n",
       "      <td>3.356653</td>\n",
       "      <td>-8.757994</td>\n",
       "      <td>0.127772</td>\n",
       "      <td>0.501482</td>\n",
       "      <td>1.838495</td>\n",
       "      <td>249.999990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Cell Saver Intake</th>\n",
       "      <td>1509.0</td>\n",
       "      <td>611.918489</td>\n",
       "      <td>422.304142</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>700.000000</td>\n",
       "      <td>7500.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Crystalloid Intake</th>\n",
       "      <td>4312.0</td>\n",
       "      <td>2544.279917</td>\n",
       "      <td>1700.689937</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1400.000000</td>\n",
       "      <td>2500.000000</td>\n",
       "      <td>3200.000000</td>\n",
       "      <td>36000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PO Intake</th>\n",
       "      <td>63597.0</td>\n",
       "      <td>183.182288</td>\n",
       "      <td>940.242562</td>\n",
       "      <td>-4080.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>120.000000</td>\n",
       "      <td>240.000000</td>\n",
       "      <td>180120.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Packed Red Blood Cells</th>\n",
       "      <td>10454.0</td>\n",
       "      <td>325.895091</td>\n",
       "      <td>92.548090</td>\n",
       "      <td>-195.999993</td>\n",
       "      <td>281.250002</td>\n",
       "      <td>350.000004</td>\n",
       "      <td>350.000063</td>\n",
       "      <td>2809.999920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Phenylephrine</th>\n",
       "      <td>46652.0</td>\n",
       "      <td>11.677646</td>\n",
       "      <td>24.682574</td>\n",
       "      <td>-189.460306</td>\n",
       "      <td>0.909091</td>\n",
       "      <td>3.143352</td>\n",
       "      <td>10.900857</td>\n",
       "      <td>250.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Piggyback</th>\n",
       "      <td>17934.0</td>\n",
       "      <td>110.837934</td>\n",
       "      <td>113.546257</td>\n",
       "      <td>-46.666665</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>99.999996</td>\n",
       "      <td>99.999997</td>\n",
       "      <td>5000.000080</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Potassium Chloride</th>\n",
       "      <td>41829.0</td>\n",
       "      <td>18.223252</td>\n",
       "      <td>8.306887</td>\n",
       "      <td>-99.933338</td>\n",
       "      <td>19.900001</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>500.000016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Solution</th>\n",
       "      <td>133523.0</td>\n",
       "      <td>38.789517</td>\n",
       "      <td>41.959803</td>\n",
       "      <td>-1600.000000</td>\n",
       "      <td>6.752085</td>\n",
       "      <td>26.433121</td>\n",
       "      <td>62.131045</td>\n",
       "      <td>4999.999836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sterile Water</th>\n",
       "      <td>11647.0</td>\n",
       "      <td>72.770775</td>\n",
       "      <td>62.563043</td>\n",
       "      <td>-175.500000</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>79.287867</td>\n",
       "      <td>99.999995</td>\n",
       "      <td>1666.666625</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              count         mean          std            min  \\\n",
       "LABEL                                                                          \n",
       "Albumin 5%                   4050.0   388.369612   166.110714    -149.999994   \n",
       "Calcium Gluconate           12193.0     2.405072     3.491139      -0.933333   \n",
       "D5 1/2NS                     8322.0   636.180349   439.026112    -918.173907   \n",
       "Dextrose 5%                106902.0   115.524221   191.605066   -5250.000000   \n",
       "Furosemide (Lasix)          21904.0    35.477109    44.378339    -120.000009   \n",
       "GT Flush                    26003.0    48.559512    63.428421   -3750.000000   \n",
       "Gastric Meds                38580.0    66.776721  1226.688211   -5400.000000   \n",
       "Heparin Sodium              14522.0  9512.448239  9765.479419 -525000.000000   \n",
       "Hydralazine                  7310.0    11.922217    28.098023    -240.000012   \n",
       "Insulin - Glargine           4127.0    23.442210    28.147084    -180.000000   \n",
       "Insulin - Humalog           12671.0     5.146176    10.454748     -30.000000   \n",
       "Insulin - Regular           65047.0     7.845160    16.835473    -140.000000   \n",
       "K Phos                       3002.0    17.227494     7.996231      -2.279736   \n",
       "KCL (Bolus)                 21302.0    54.950031    33.179979     -23.333332   \n",
       "LR                          29414.0   655.032208   416.998701  -23000.000000   \n",
       "Lorazepam (Ativan)           9660.0     1.379741     3.178132    -120.000002   \n",
       "Magnesium Sulfate           13120.0     2.048632     2.497431      -0.733333   \n",
       "Magnesium Sulfate (Bolus)    9281.0    49.575188     6.207162     -10.000000   \n",
       "Metoprolol                  15485.0     5.756933     4.152228    -180.000018   \n",
       "Midazolam (Versed)          33687.0    17.852877    33.090963     -38.000002   \n",
       "Morphine Sulfate            22765.0     4.993317    19.674722     -60.000003   \n",
       "Nitroglycerin               21664.0    11.542607    22.662372     -19.000001   \n",
       "Norepinephrine              34950.0     1.794691     3.356653      -8.757994   \n",
       "OR Cell Saver Intake         1509.0   611.918489   422.304142       0.000000   \n",
       "OR Crystalloid Intake        4312.0  2544.279917  1700.689937       0.000000   \n",
       "PO Intake                   63597.0   183.182288   940.242562   -4080.000000   \n",
       "Packed Red Blood Cells      10454.0   325.895091    92.548090    -195.999993   \n",
       "Phenylephrine               46652.0    11.677646    24.682574    -189.460306   \n",
       "Piggyback                   17934.0   110.837934   113.546257     -46.666665   \n",
       "Potassium Chloride          41829.0    18.223252     8.306887     -99.933338   \n",
       "Solution                   133523.0    38.789517    41.959803   -1600.000000   \n",
       "Sterile Water               11647.0    72.770775    62.563043    -175.500000   \n",
       "\n",
       "                                   25%          50%           75%  \\\n",
       "LABEL                                                               \n",
       "Albumin 5%                  249.999990   499.999980    499.999980   \n",
       "Calcium Gluconate             2.000000     2.000000      2.000000   \n",
       "D5 1/2NS                    201.666662   778.314861    999.999972   \n",
       "Dextrose 5%                   6.577475    47.717591    153.333326   \n",
       "Furosemide (Lasix)           16.098319    20.000001     40.000003   \n",
       "GT Flush                     30.000000    30.000000     50.000000   \n",
       "Gastric Meds                 30.000000    40.000000     60.000000   \n",
       "Heparin Sodium             2157.095630  6858.147894  15555.605203   \n",
       "Hydralazine                  10.000001    10.000001     10.000001   \n",
       "Insulin - Glargine           10.000000    20.000000     30.000000   \n",
       "Insulin - Humalog             2.000000     4.000000      6.000000   \n",
       "Insulin - Regular             2.000000     4.000000      8.000000   \n",
       "K Phos                       15.000000    15.000001     16.753996   \n",
       "KCL (Bolus)                  49.999999    49.999999     49.999999   \n",
       "LR                          400.000000   664.782125    999.999984   \n",
       "Lorazepam (Ativan)            0.500000     1.000000      2.000000   \n",
       "Magnesium Sulfate             2.000000     2.000000      2.000000   \n",
       "Magnesium Sulfate (Bolus)    49.999999    49.999999     49.999999   \n",
       "Metoprolol                    5.000000     5.000000      5.000000   \n",
       "Midazolam (Versed)            1.000000     2.000000     16.989001   \n",
       "Morphine Sulfate              2.000000     2.000000      3.333333   \n",
       "Nitroglycerin                 0.919592     2.716225      9.104737   \n",
       "Norepinephrine                0.127772     0.501482      1.838495   \n",
       "OR Cell Saver Intake        500.000000   500.000000    700.000000   \n",
       "OR Crystalloid Intake      1400.000000  2500.000000   3200.000000   \n",
       "PO Intake                   100.000000   120.000000    240.000000   \n",
       "Packed Red Blood Cells      281.250002   350.000004    350.000063   \n",
       "Phenylephrine                 0.909091     3.143352     10.900857   \n",
       "Piggyback                    49.999999    99.999996     99.999997   \n",
       "Potassium Chloride           19.900001    20.000000     20.000000   \n",
       "Solution                      6.752085    26.433121     62.131045   \n",
       "Sterile Water                49.999999    79.287867     99.999995   \n",
       "\n",
       "                                     max  \n",
       "LABEL                                     \n",
       "Albumin 5%                   5199.999792  \n",
       "Calcium Gluconate             199.999998  \n",
       "D5 1/2NS                     5999.999904  \n",
       "Dextrose 5%                  5000.000040  \n",
       "Furosemide (Lasix)           2320.000200  \n",
       "GT Flush                     2000.000000  \n",
       "Gastric Meds               240120.000000  \n",
       "Heparin Sodium              30640.000300  \n",
       "Hydralazine                  2350.000100  \n",
       "Insulin - Glargine           1515.000000  \n",
       "Insulin - Humalog             900.000000  \n",
       "Insulin - Regular            2499.999996  \n",
       "K Phos                         83.000005  \n",
       "KCL (Bolus)                  1000.000000  \n",
       "LR                          16855.000000  \n",
       "Lorazepam (Ativan)            113.283334  \n",
       "Magnesium Sulfate             249.999967  \n",
       "Magnesium Sulfate (Bolus)     249.999990  \n",
       "Metoprolol                    125.000000  \n",
       "Midazolam (Versed)           1710.134060  \n",
       "Morphine Sulfate             1945.000100  \n",
       "Nitroglycerin                 200.000006  \n",
       "Norepinephrine                249.999990  \n",
       "OR Cell Saver Intake         7500.000000  \n",
       "OR Crystalloid Intake       36000.000000  \n",
       "PO Intake                  180120.000000  \n",
       "Packed Red Blood Cells       2809.999920  \n",
       "Phenylephrine                 250.000000  \n",
       "Piggyback                    5000.000080  \n",
       "Potassium Chloride            500.000016  \n",
       "Solution                     4999.999836  \n",
       "Sterile Water                1666.666625  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs_small_3.groupby(\"LABEL\")[\"AMOUNT\"].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Empty DataFrame\n",
      "Columns: [SUBJECT_ID, HADM_ID, STARTTIME, ENDTIME, ITEMID, AMOUNT, AMOUNTUOM, RATE, RATEUOM, PATIENTWEIGHT, ORDERCATEGORYDESCRIPTION, LABEL, DURATION]\n",
      "Index: []\n"
     ]
    }
   ],
   "source": [
    "#Clean Albumin 5%\n",
    "#Invert start time and end time\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Albumin 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Albumin 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Albumin 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Albumin 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Albumin 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"AMOUNT\"]*=-1\n",
    "\n",
    "#Clean Calcium Gluconate\n",
    "#Invert start time and end time\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Calcium Gluconate\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Calcium Gluconate\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Calcium Gluconate\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Calcium Gluconate\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Calcium Gluconate\") & (inputs_small_3[\"AMOUNT\"]<0),\"AMOUNT\"]*=-1\n",
    "#Remove entries with more 10 grams.\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Calcium Gluconate\") & (inputs_small_3[\"AMOUNT\"]>10)].index).copy()\n",
    "\n",
    "\n",
    "#Clean Cefazolin\n",
    "#Invert start time and end time\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefazolin\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefazolin\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefazolin\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefazolin\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefazolin\") & (inputs_small_3[\"AMOUNT\"]<0),\"AMOUNT\"]*=-1\n",
    "#Remove entries with more than 2 doses amount.\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefazolin\") & (inputs_small_3[\"AMOUNT\"]>2)].index).copy()\n",
    "\n",
    "#Clean Cefepime\n",
    "#Remove the negative entries (they are anyway too large in the positive range as well.)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Cefepime\") & (inputs_small_3[\"AMOUNT\"]<0)].index).copy()\n",
    "\n",
    "#Clean Ceftriaxone\n",
    "#Remove the negative entries (they are anyway too large in the positive range as well.)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Ceftriaxone\") & (inputs_small_3[\"AMOUNT\"]<0)].index).copy()\n",
    "\n",
    "#Clean Ciprofloxacin\n",
    "#Remove the negative entries (they are anyway too large in the positive range as well.)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Ciprofloxacin\") & (inputs_small_3[\"AMOUNT\"]<0)].index).copy()\n",
    "\n",
    "#Clean D5 1/2NS\n",
    "#Invert start time and end time\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"D5 1/2NS\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"D5 1/2NS\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"D5 1/2NS\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"D5 1/2NS\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"D5 1/2NS\") & (inputs_small_3[\"AMOUNT\"]<0),\"AMOUNT\"]*=-1\n",
    "\n",
    "#Clean Dextrose 5%\n",
    "#Invert start time and end time\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Dextrose 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Dextrose 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Dextrose 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Dextrose 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Dextrose 5%\") & (inputs_small_3[\"AMOUNT\"]<0),\"AMOUNT\"]*=-1\n",
    "\n",
    "#Clean Famotidine (Pepcid)\n",
    "#Remove the negative entries (they are anyway too large in the positive range as well.)\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Famotidine (Pepcid)\") & (inputs_small_3[\"AMOUNT\"]<0)].index).copy()\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Famotidine (Pepcid)\") & (inputs_small_3[\"AMOUNT\"]>1)].index).copy()\n",
    "\n",
    "#Clean Fentanyl\n",
    "#Invert start time and end time\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl\") & (inputs_small_3[\"AMOUNT\"]<0),\"AMOUNT\"]*=-1\n",
    "\n",
    "#Clean Fentanyl (Concentrate)\n",
    "#Invert start time and end time\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNT\"]<0),\"STARTTIME\"]=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNT\"]<0),\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Fentanyl (Concentrate)\") & (inputs_small_3[\"AMOUNT\"]<0),\"AMOUNT\"]*=-1\n",
    "\n",
    "\n",
    "#Check if all remaining negative values are linked to the swapping the start and end times.\n",
    "inputs_small_3['STARTTIME']=pd.to_datetime(inputs_small_3[\"STARTTIME\"], format='%Y-%m-%d %H:%M:%S')\n",
    "inputs_small_3['ENDTIME']=pd.to_datetime(inputs_small_3[\"ENDTIME\"], format='%Y-%m-%d %H:%M:%S')\n",
    "inputs_small_3[\"DURATION\"]=inputs_small_3['ENDTIME']-inputs_small_3['STARTTIME']\n",
    "print(inputs_small_3.loc[(inputs_small_3[\"AMOUNT\"]<0)&(inputs_small_3[\"DURATION\"]>timedelta(0))]) #All are inverted\n",
    "\n",
    "#Revert all the remaining negative values to the positive range.\n",
    "a=inputs_small_3.loc[inputs_small_3[\"AMOUNT\"]<0,\"STARTTIME\"]\n",
    "inputs_small_3.loc[inputs_small_3[\"AMOUNT\"]<0,\"STARTTIME\"]=inputs_small_3.loc[inputs_small_3[\"AMOUNT\"]<0,\"ENDTIME\"]\n",
    "a=inputs_small_3.loc[inputs_small_3[\"AMOUNT\"]<0,\"ENDTIME\"]=a\n",
    "#Positive rate\n",
    "inputs_small_3.loc[inputs_small_3[\"AMOUNT\"]<0,\"AMOUNT\"]*=-1\n",
    "#Recompute the durations with the correct time stamps for start and end.\n",
    "inputs_small_3[\"DURATION\"]=inputs_small_3['ENDTIME']-inputs_small_3['STARTTIME']\n",
    "\n",
    "#Clean Gastric Meds, remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Gastric Meds\") & (inputs_small_3[\"AMOUNT\"]>5000)].index).copy()\n",
    "\n",
    "#Clean Heparin Sodium, remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Heparin Sodium\") & (inputs_small_3[\"AMOUNT\"]>50000)].index).copy()\n",
    "\n",
    "#Clean Heparin Sodium (Prophylaxis), remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Heparin Sodium (Prophylaxis)\") & (inputs_small_3[\"AMOUNT\"]>2)].index).copy()\n",
    "\n",
    "#Clean Hydralazine, remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Hydralazine\") & (inputs_small_3[\"AMOUNT\"]>200)].index).copy()\n",
    "\n",
    "#Clean Hydromorphone (Dilaudid), remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Hydromorphone (Dilaudid)\") & (inputs_small_3[\"AMOUNT\"]>500)].index).copy()\n",
    "\n",
    "#Clean Insulin - Humalog, remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Insulin - Humalog\") & (inputs_small_3[\"AMOUNT\"]>100)].index).copy()\n",
    "\n",
    "#Clean Insulin - Regular, remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Insulin - Regular\") & (inputs_small_3[\"AMOUNT\"]>1000)].index).copy()\n",
    "\n",
    "#Clean Magnesium Sulfate, remove too large values\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"Magnesium Sulfate\") & (inputs_small_3[\"AMOUNT\"]>51)].index).copy()\n",
    "\n",
    "#To be continued ..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2) In rates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LABEL</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albumin 5%</th>\n",
       "      <td>4050.0</td>\n",
       "      <td>466.432805</td>\n",
       "      <td>249.881876</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>249.999990</td>\n",
       "      <td>499.999980</td>\n",
       "      <td>499.999980</td>\n",
       "      <td>4.285714e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Calcium Gluconate</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D5 1/2NS</th>\n",
       "      <td>8299.0</td>\n",
       "      <td>107.856254</td>\n",
       "      <td>679.450735</td>\n",
       "      <td>1.006036</td>\n",
       "      <td>75.000000</td>\n",
       "      <td>80.002686</td>\n",
       "      <td>100.502514</td>\n",
       "      <td>5.959800e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dextrose 5%</th>\n",
       "      <td>106902.0</td>\n",
       "      <td>44.410480</td>\n",
       "      <td>336.420551</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.628070</td>\n",
       "      <td>14.985362</td>\n",
       "      <td>30.133583</td>\n",
       "      <td>2.537500e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furosemide (Lasix)</th>\n",
       "      <td>8843.0</td>\n",
       "      <td>9.198524</td>\n",
       "      <td>10.810320</td>\n",
       "      <td>0.050000</td>\n",
       "      <td>4.457647</td>\n",
       "      <td>7.996508</td>\n",
       "      <td>12.038351</td>\n",
       "      <td>6.357810e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GT Flush</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gastric Meds</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heparin Sodium</th>\n",
       "      <td>13411.0</td>\n",
       "      <td>1960.233342</td>\n",
       "      <td>16709.719397</td>\n",
       "      <td>10.500053</td>\n",
       "      <td>900.609870</td>\n",
       "      <td>1218.853140</td>\n",
       "      <td>1662.627330</td>\n",
       "      <td>1.500000e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hydralazine</th>\n",
       "      <td>2.0</td>\n",
       "      <td>45.000004</td>\n",
       "      <td>7.071069</td>\n",
       "      <td>40.000003</td>\n",
       "      <td>42.500004</td>\n",
       "      <td>45.000004</td>\n",
       "      <td>47.500004</td>\n",
       "      <td>5.000000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Glargine</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Humalog</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Regular</th>\n",
       "      <td>30519.0</td>\n",
       "      <td>6.022688</td>\n",
       "      <td>26.277556</td>\n",
       "      <td>0.100014</td>\n",
       "      <td>2.001317</td>\n",
       "      <td>4.000618</td>\n",
       "      <td>6.517845</td>\n",
       "      <td>3.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K Phos</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KCL (Bolus)</th>\n",
       "      <td>21302.0</td>\n",
       "      <td>53.602011</td>\n",
       "      <td>15.284899</td>\n",
       "      <td>4.524887</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>5.000000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LR</th>\n",
       "      <td>18543.0</td>\n",
       "      <td>237.526887</td>\n",
       "      <td>497.859707</td>\n",
       "      <td>2.772277</td>\n",
       "      <td>75.065754</td>\n",
       "      <td>100.003344</td>\n",
       "      <td>150.000000</td>\n",
       "      <td>3.000000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lorazepam (Ativan)</th>\n",
       "      <td>104.0</td>\n",
       "      <td>4.404800</td>\n",
       "      <td>2.679658</td>\n",
       "      <td>0.248074</td>\n",
       "      <td>2.001733</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>6.015076</td>\n",
       "      <td>9.617822e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate (Bolus)</th>\n",
       "      <td>9281.0</td>\n",
       "      <td>52.001510</td>\n",
       "      <td>18.263725</td>\n",
       "      <td>13.953489</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>1.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Metoprolol</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Midazolam (Versed)</th>\n",
       "      <td>19412.0</td>\n",
       "      <td>6.387720</td>\n",
       "      <td>33.696787</td>\n",
       "      <td>0.025000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>7.031338</td>\n",
       "      <td>2.465550e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morphine Sulfate</th>\n",
       "      <td>2004.0</td>\n",
       "      <td>12.660172</td>\n",
       "      <td>39.740092</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>4.001368</td>\n",
       "      <td>8.002721</td>\n",
       "      <td>14.998502</td>\n",
       "      <td>1.604593e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nitroglycerin</th>\n",
       "      <td>21664.0</td>\n",
       "      <td>1.567709</td>\n",
       "      <td>5.195948</td>\n",
       "      <td>0.021200</td>\n",
       "      <td>0.500305</td>\n",
       "      <td>1.000592</td>\n",
       "      <td>2.000026</td>\n",
       "      <td>3.236247e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Norepinephrine</th>\n",
       "      <td>34950.0</td>\n",
       "      <td>0.201516</td>\n",
       "      <td>2.140389</td>\n",
       "      <td>0.000200</td>\n",
       "      <td>0.059426</td>\n",
       "      <td>0.110777</td>\n",
       "      <td>0.230208</td>\n",
       "      <td>3.595506e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Cell Saver Intake</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Crystalloid Intake</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PO Intake</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Packed Red Blood Cells</th>\n",
       "      <td>10454.0</td>\n",
       "      <td>380.226137</td>\n",
       "      <td>1746.265764</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>160.305348</td>\n",
       "      <td>281.250000</td>\n",
       "      <td>351.562500</td>\n",
       "      <td>1.680000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Phenylephrine</th>\n",
       "      <td>46652.0</td>\n",
       "      <td>1.603649</td>\n",
       "      <td>9.351598</td>\n",
       "      <td>0.004998</td>\n",
       "      <td>0.500165</td>\n",
       "      <td>0.999473</td>\n",
       "      <td>1.793272</td>\n",
       "      <td>9.744446e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Piggyback</th>\n",
       "      <td>17934.0</td>\n",
       "      <td>128.018719</td>\n",
       "      <td>148.002975</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>99.999996</td>\n",
       "      <td>99.999996</td>\n",
       "      <td>1.000000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Potassium Chloride</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Solution</th>\n",
       "      <td>115980.0</td>\n",
       "      <td>20.846113</td>\n",
       "      <td>44.905806</td>\n",
       "      <td>0.004000</td>\n",
       "      <td>7.746008</td>\n",
       "      <td>17.142858</td>\n",
       "      <td>28.678726</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sterile Water</th>\n",
       "      <td>11605.0</td>\n",
       "      <td>41.453264</td>\n",
       "      <td>119.160203</td>\n",
       "      <td>0.660337</td>\n",
       "      <td>20.074575</td>\n",
       "      <td>30.047246</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              count         mean           std        min  \\\n",
       "LABEL                                                                       \n",
       "Albumin 5%                   4050.0   466.432805    249.881876  25.000000   \n",
       "Calcium Gluconate               0.0          NaN           NaN        NaN   \n",
       "D5 1/2NS                     8299.0   107.856254    679.450735   1.006036   \n",
       "Dextrose 5%                106902.0    44.410480    336.420551   0.000000   \n",
       "Furosemide (Lasix)           8843.0     9.198524     10.810320   0.050000   \n",
       "GT Flush                        0.0          NaN           NaN        NaN   \n",
       "Gastric Meds                    0.0          NaN           NaN        NaN   \n",
       "Heparin Sodium              13411.0  1960.233342  16709.719397  10.500053   \n",
       "Hydralazine                     2.0    45.000004      7.071069  40.000003   \n",
       "Insulin - Glargine              0.0          NaN           NaN        NaN   \n",
       "Insulin - Humalog               0.0          NaN           NaN        NaN   \n",
       "Insulin - Regular           30519.0     6.022688     26.277556   0.100014   \n",
       "K Phos                          0.0          NaN           NaN        NaN   \n",
       "KCL (Bolus)                 21302.0    53.602011     15.284899   4.524887   \n",
       "LR                          18543.0   237.526887    497.859707   2.772277   \n",
       "Lorazepam (Ativan)            104.0     4.404800      2.679658   0.248074   \n",
       "Magnesium Sulfate               0.0          NaN           NaN        NaN   \n",
       "Magnesium Sulfate (Bolus)    9281.0    52.001510     18.263725  13.953489   \n",
       "Metoprolol                      0.0          NaN           NaN        NaN   \n",
       "Midazolam (Versed)          19412.0     6.387720     33.696787   0.025000   \n",
       "Morphine Sulfate             2004.0    12.660172     39.740092   0.500000   \n",
       "Nitroglycerin               21664.0     1.567709      5.195948   0.021200   \n",
       "Norepinephrine              34950.0     0.201516      2.140389   0.000200   \n",
       "OR Cell Saver Intake            0.0          NaN           NaN        NaN   \n",
       "OR Crystalloid Intake           0.0          NaN           NaN        NaN   \n",
       "PO Intake                       0.0          NaN           NaN        NaN   \n",
       "Packed Red Blood Cells      10454.0   380.226137   1746.265764   1.000000   \n",
       "Phenylephrine               46652.0     1.603649      9.351598   0.004998   \n",
       "Piggyback                   17934.0   128.018719    148.002975   1.000000   \n",
       "Potassium Chloride              0.0          NaN           NaN        NaN   \n",
       "Solution                   115980.0    20.846113     44.905806   0.004000   \n",
       "Sterile Water               11605.0    41.453264    119.160203   0.660337   \n",
       "\n",
       "                                  25%          50%          75%           max  \n",
       "LABEL                                                                          \n",
       "Albumin 5%                 249.999990   499.999980   499.999980  4.285714e+03  \n",
       "Calcium Gluconate                 NaN          NaN          NaN           NaN  \n",
       "D5 1/2NS                    75.000000    80.002686   100.502514  5.959800e+04  \n",
       "Dextrose 5%                  9.628070    14.985362    30.133583  2.537500e+04  \n",
       "Furosemide (Lasix)           4.457647     7.996508    12.038351  6.357810e+02  \n",
       "GT Flush                          NaN          NaN          NaN           NaN  \n",
       "Gastric Meds                      NaN          NaN          NaN           NaN  \n",
       "Heparin Sodium             900.609870  1218.853140  1662.627330  1.500000e+06  \n",
       "Hydralazine                 42.500004    45.000004    47.500004  5.000000e+01  \n",
       "Insulin - Glargine                NaN          NaN          NaN           NaN  \n",
       "Insulin - Humalog                 NaN          NaN          NaN           NaN  \n",
       "Insulin - Regular            2.001317     4.000618     6.517845  3.000000e+03  \n",
       "K Phos                            NaN          NaN          NaN           NaN  \n",
       "KCL (Bolus)                 49.999999    49.999999    49.999999  5.000000e+02  \n",
       "LR                          75.065754   100.003344   150.000000  3.000000e+04  \n",
       "Lorazepam (Ativan)           2.001733     4.000000     6.015076  9.617822e+00  \n",
       "Magnesium Sulfate                 NaN          NaN          NaN           NaN  \n",
       "Magnesium Sulfate (Bolus)   49.999999    49.999999    49.999999  1.000000e+03  \n",
       "Metoprolol                        NaN          NaN          NaN           NaN  \n",
       "Midazolam (Versed)           2.000000     4.000000     7.031338  2.465550e+03  \n",
       "Morphine Sulfate             4.001368     8.002721    14.998502  1.604593e+03  \n",
       "Nitroglycerin                0.500305     1.000592     2.000026  3.236247e+02  \n",
       "Norepinephrine               0.059426     0.110777     0.230208  3.595506e+02  \n",
       "OR Cell Saver Intake              NaN          NaN          NaN           NaN  \n",
       "OR Crystalloid Intake             NaN          NaN          NaN           NaN  \n",
       "PO Intake                         NaN          NaN          NaN           NaN  \n",
       "Packed Red Blood Cells     160.305348   281.250000   351.562500  1.680000e+05  \n",
       "Phenylephrine                0.500165     0.999473     1.793272  9.744446e+02  \n",
       "Piggyback                   49.999999    99.999996    99.999996  1.000000e+04  \n",
       "Potassium Chloride                NaN          NaN          NaN           NaN  \n",
       "Solution                     7.746008    17.142858    28.678726  6.000000e+03  \n",
       "Sterile Water               20.074575    30.047246    49.999999  6.000000e+03  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs_small_3.groupby(\"LABEL\")[\"RATE\"].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Clean D5 1/2NS Remove too large rates\n",
    "inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==\"D5 1/2NS\") & (inputs_small_3[\"RATE\"]>1000)].index).copy()\n",
    "\n",
    "#Remove all entries whose rate is more than 4 std away from the mean.\n",
    "rate_desc=inputs_small_3.groupby(\"LABEL\")[\"RATE\"].describe()\n",
    "name_list=list(rate_desc.loc[rate_desc[\"count\"]!=0].index)\n",
    "for label in name_list:\n",
    "    inputs_small_3=inputs_small_3.drop(inputs_small_3.loc[(inputs_small_3[\"LABEL\"]==label)&(inputs_small_3[\"RATE\"]>(rate_desc.loc[label,\"mean\"]+4*rate_desc.loc[label,\"std\"]))].index).copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LABEL</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albumin 5%</th>\n",
       "      <td>4040.0</td>\n",
       "      <td>462.461521</td>\n",
       "      <td>234.013232</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>249.999990</td>\n",
       "      <td>499.999980</td>\n",
       "      <td>499.999980</td>\n",
       "      <td>1250.000040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Calcium Gluconate</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D5 1/2NS</th>\n",
       "      <td>8202.0</td>\n",
       "      <td>89.741701</td>\n",
       "      <td>46.449467</td>\n",
       "      <td>1.006036</td>\n",
       "      <td>75.000000</td>\n",
       "      <td>80.000004</td>\n",
       "      <td>100.214476</td>\n",
       "      <td>399.999990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dextrose 5%</th>\n",
       "      <td>106684.0</td>\n",
       "      <td>34.317221</td>\n",
       "      <td>77.575143</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.600108</td>\n",
       "      <td>14.974345</td>\n",
       "      <td>30.071384</td>\n",
       "      <td>1365.879240</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furosemide (Lasix)</th>\n",
       "      <td>8828.0</td>\n",
       "      <td>8.952322</td>\n",
       "      <td>6.026809</td>\n",
       "      <td>0.050000</td>\n",
       "      <td>4.246872</td>\n",
       "      <td>7.996272</td>\n",
       "      <td>12.033467</td>\n",
       "      <td>51.974998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GT Flush</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gastric Meds</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heparin Sodium</th>\n",
       "      <td>13375.0</td>\n",
       "      <td>1417.969830</td>\n",
       "      <td>1397.500690</td>\n",
       "      <td>10.500053</td>\n",
       "      <td>900.555060</td>\n",
       "      <td>1217.110980</td>\n",
       "      <td>1655.834310</td>\n",
       "      <td>66398.172000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hydralazine</th>\n",
       "      <td>2.0</td>\n",
       "      <td>45.000004</td>\n",
       "      <td>7.071069</td>\n",
       "      <td>40.000003</td>\n",
       "      <td>42.500004</td>\n",
       "      <td>45.000004</td>\n",
       "      <td>47.500004</td>\n",
       "      <td>50.000005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Glargine</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Humalog</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Regular</th>\n",
       "      <td>30497.0</td>\n",
       "      <td>5.570054</td>\n",
       "      <td>6.166659</td>\n",
       "      <td>0.100014</td>\n",
       "      <td>2.001313</td>\n",
       "      <td>4.000509</td>\n",
       "      <td>6.513278</td>\n",
       "      <td>105.660954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K Phos</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KCL (Bolus)</th>\n",
       "      <td>21198.0</td>\n",
       "      <td>53.104374</td>\n",
       "      <td>12.778303</td>\n",
       "      <td>4.524887</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>111.111108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LR</th>\n",
       "      <td>18493.0</td>\n",
       "      <td>225.259102</td>\n",
       "      <td>337.676086</td>\n",
       "      <td>2.772277</td>\n",
       "      <td>75.060156</td>\n",
       "      <td>100.000170</td>\n",
       "      <td>150.000000</td>\n",
       "      <td>2222.222220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lorazepam (Ativan)</th>\n",
       "      <td>104.0</td>\n",
       "      <td>4.404800</td>\n",
       "      <td>2.679658</td>\n",
       "      <td>0.248074</td>\n",
       "      <td>2.001733</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>6.015076</td>\n",
       "      <td>9.617822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate (Bolus)</th>\n",
       "      <td>9233.0</td>\n",
       "      <td>51.044649</td>\n",
       "      <td>7.486249</td>\n",
       "      <td>13.953489</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>120.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Metoprolol</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Midazolam (Versed)</th>\n",
       "      <td>19392.0</td>\n",
       "      <td>5.714411</td>\n",
       "      <td>6.987860</td>\n",
       "      <td>0.025000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>7.019833</td>\n",
       "      <td>120.000006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morphine Sulfate</th>\n",
       "      <td>2001.0</td>\n",
       "      <td>11.490703</td>\n",
       "      <td>11.554609</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>4.001368</td>\n",
       "      <td>8.002687</td>\n",
       "      <td>14.997699</td>\n",
       "      <td>104.206362</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nitroglycerin</th>\n",
       "      <td>21633.0</td>\n",
       "      <td>1.424940</td>\n",
       "      <td>1.176317</td>\n",
       "      <td>0.021200</td>\n",
       "      <td>0.500300</td>\n",
       "      <td>1.000580</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>21.634409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Norepinephrine</th>\n",
       "      <td>34929.0</td>\n",
       "      <td>0.174721</td>\n",
       "      <td>0.281684</td>\n",
       "      <td>0.000200</td>\n",
       "      <td>0.059411</td>\n",
       "      <td>0.110632</td>\n",
       "      <td>0.229947</td>\n",
       "      <td>8.714598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Cell Saver Intake</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Crystalloid Intake</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PO Intake</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Packed Red Blood Cells</th>\n",
       "      <td>10438.0</td>\n",
       "      <td>348.225142</td>\n",
       "      <td>405.981950</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>160.221963</td>\n",
       "      <td>281.125002</td>\n",
       "      <td>351.562500</td>\n",
       "      <td>5625.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Phenylephrine</th>\n",
       "      <td>46595.0</td>\n",
       "      <td>1.370237</td>\n",
       "      <td>1.498969</td>\n",
       "      <td>0.004998</td>\n",
       "      <td>0.500163</td>\n",
       "      <td>0.999439</td>\n",
       "      <td>1.787808</td>\n",
       "      <td>37.722284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Piggyback</th>\n",
       "      <td>17843.0</td>\n",
       "      <td>122.626850</td>\n",
       "      <td>103.631593</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>99.999996</td>\n",
       "      <td>99.999996</td>\n",
       "      <td>703.125000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Potassium Chloride</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Solution</th>\n",
       "      <td>115877.0</td>\n",
       "      <td>20.175119</td>\n",
       "      <td>16.288772</td>\n",
       "      <td>0.004000</td>\n",
       "      <td>7.741935</td>\n",
       "      <td>17.132642</td>\n",
       "      <td>28.639054</td>\n",
       "      <td>199.999998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sterile Water</th>\n",
       "      <td>11592.0</td>\n",
       "      <td>38.698560</td>\n",
       "      <td>34.579311</td>\n",
       "      <td>0.660337</td>\n",
       "      <td>20.073529</td>\n",
       "      <td>30.043666</td>\n",
       "      <td>49.999999</td>\n",
       "      <td>499.999980</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              count         mean          std        min  \\\n",
       "LABEL                                                                      \n",
       "Albumin 5%                   4040.0   462.461521   234.013232  25.000000   \n",
       "Calcium Gluconate               0.0          NaN          NaN        NaN   \n",
       "D5 1/2NS                     8202.0    89.741701    46.449467   1.006036   \n",
       "Dextrose 5%                106684.0    34.317221    77.575143   0.000000   \n",
       "Furosemide (Lasix)           8828.0     8.952322     6.026809   0.050000   \n",
       "GT Flush                        0.0          NaN          NaN        NaN   \n",
       "Gastric Meds                    0.0          NaN          NaN        NaN   \n",
       "Heparin Sodium              13375.0  1417.969830  1397.500690  10.500053   \n",
       "Hydralazine                     2.0    45.000004     7.071069  40.000003   \n",
       "Insulin - Glargine              0.0          NaN          NaN        NaN   \n",
       "Insulin - Humalog               0.0          NaN          NaN        NaN   \n",
       "Insulin - Regular           30497.0     5.570054     6.166659   0.100014   \n",
       "K Phos                          0.0          NaN          NaN        NaN   \n",
       "KCL (Bolus)                 21198.0    53.104374    12.778303   4.524887   \n",
       "LR                          18493.0   225.259102   337.676086   2.772277   \n",
       "Lorazepam (Ativan)            104.0     4.404800     2.679658   0.248074   \n",
       "Magnesium Sulfate               0.0          NaN          NaN        NaN   \n",
       "Magnesium Sulfate (Bolus)    9233.0    51.044649     7.486249  13.953489   \n",
       "Metoprolol                      0.0          NaN          NaN        NaN   \n",
       "Midazolam (Versed)          19392.0     5.714411     6.987860   0.025000   \n",
       "Morphine Sulfate             2001.0    11.490703    11.554609   0.500000   \n",
       "Nitroglycerin               21633.0     1.424940     1.176317   0.021200   \n",
       "Norepinephrine              34929.0     0.174721     0.281684   0.000200   \n",
       "OR Cell Saver Intake            0.0          NaN          NaN        NaN   \n",
       "OR Crystalloid Intake           0.0          NaN          NaN        NaN   \n",
       "PO Intake                       0.0          NaN          NaN        NaN   \n",
       "Packed Red Blood Cells      10438.0   348.225142   405.981950   1.000000   \n",
       "Phenylephrine               46595.0     1.370237     1.498969   0.004998   \n",
       "Piggyback                   17843.0   122.626850   103.631593   1.000000   \n",
       "Potassium Chloride              0.0          NaN          NaN        NaN   \n",
       "Solution                   115877.0    20.175119    16.288772   0.004000   \n",
       "Sterile Water               11592.0    38.698560    34.579311   0.660337   \n",
       "\n",
       "                                  25%          50%          75%           max  \n",
       "LABEL                                                                          \n",
       "Albumin 5%                 249.999990   499.999980   499.999980   1250.000040  \n",
       "Calcium Gluconate                 NaN          NaN          NaN           NaN  \n",
       "D5 1/2NS                    75.000000    80.000004   100.214476    399.999990  \n",
       "Dextrose 5%                  9.600108    14.974345    30.071384   1365.879240  \n",
       "Furosemide (Lasix)           4.246872     7.996272    12.033467     51.974998  \n",
       "GT Flush                          NaN          NaN          NaN           NaN  \n",
       "Gastric Meds                      NaN          NaN          NaN           NaN  \n",
       "Heparin Sodium             900.555060  1217.110980  1655.834310  66398.172000  \n",
       "Hydralazine                 42.500004    45.000004    47.500004     50.000005  \n",
       "Insulin - Glargine                NaN          NaN          NaN           NaN  \n",
       "Insulin - Humalog                 NaN          NaN          NaN           NaN  \n",
       "Insulin - Regular            2.001313     4.000509     6.513278    105.660954  \n",
       "K Phos                            NaN          NaN          NaN           NaN  \n",
       "KCL (Bolus)                 49.999999    49.999999    49.999999    111.111108  \n",
       "LR                          75.060156   100.000170   150.000000   2222.222220  \n",
       "Lorazepam (Ativan)           2.001733     4.000000     6.015076      9.617822  \n",
       "Magnesium Sulfate                 NaN          NaN          NaN           NaN  \n",
       "Magnesium Sulfate (Bolus)   49.999999    49.999999    49.999999    120.000000  \n",
       "Metoprolol                        NaN          NaN          NaN           NaN  \n",
       "Midazolam (Versed)           2.000000     4.000000     7.019833    120.000006  \n",
       "Morphine Sulfate             4.001368     8.002687    14.997699    104.206362  \n",
       "Nitroglycerin                0.500300     1.000580     2.000000     21.634409  \n",
       "Norepinephrine               0.059411     0.110632     0.229947      8.714598  \n",
       "OR Cell Saver Intake              NaN          NaN          NaN           NaN  \n",
       "OR Crystalloid Intake             NaN          NaN          NaN           NaN  \n",
       "PO Intake                         NaN          NaN          NaN           NaN  \n",
       "Packed Red Blood Cells     160.221963   281.125002   351.562500   5625.000000  \n",
       "Phenylephrine                0.500163     0.999439     1.787808     37.722284  \n",
       "Piggyback                   49.999999    99.999996    99.999996    703.125000  \n",
       "Potassium Chloride                NaN          NaN          NaN           NaN  \n",
       "Solution                     7.741935    17.132642    28.639054    199.999998  \n",
       "Sterile Water               20.073529    30.043666    49.999999    499.999980  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs_small_3.groupby(\"LABEL\")[\"RATE\"].describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## We now split the entries which are spread in time.\n",
    "\n",
    "We chose the duration window for the sampling. here we choose 30 minutes. So every entry which has a rate and with duration larger than 1 hour, we split it into fixed times injections.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "#First we check if when there is a duration, the amount is matching.\n",
    "\n",
    "#First check the /hours units\n",
    "df_temp=inputs_small_3.loc[(inputs_small_3[\"RATE\"].notnull()) & (inputs_small_3[\"RATEUOM\"].str.contains(\"hour\"))].copy()\n",
    "df_temp[\"COMPUTED_AMOUNT\"]=df_temp[\"RATE\"]*(df_temp[\"DURATION\"].dt.total_seconds()/3600)\n",
    "\n",
    "#Check with a 0.01 tolerance\n",
    "assert(len(df_temp.loc[(abs(df_temp[\"COMPUTED_AMOUNT\"]-df_temp[\"AMOUNT\"])>0.01)].index)==0) #OK\n",
    "\n",
    "#Second check the /min units\n",
    "df_temp=inputs_small_3.loc[(inputs_small_3[\"RATE\"].notnull()) & (inputs_small_3[\"RATEUOM\"].str.contains(\"mL/min\"))].copy()\n",
    "df_temp[\"COMPUTED_AMOUNT\"]=df_temp[\"RATE\"]*(df_temp[\"DURATION\"].dt.total_seconds()/60)\n",
    "\n",
    "#Check with a 0.01 tolerance\n",
    "assert(len(df_temp.loc[(abs(df_temp[\"COMPUTED_AMOUNT\"]-df_temp[\"AMOUNT\"])>0.01)].index)==0) #OK\n",
    "\n",
    "#Third check the kg/min units\n",
    "df_temp=inputs_small_3.loc[(inputs_small_3[\"RATE\"].notnull()) & (inputs_small_3[\"RATEUOM\"].str.contains(\"kg/min\"))].copy()\n",
    "df_temp[\"COMPUTED_AMOUNT\"]=df_temp[\"RATE\"]*(df_temp[\"DURATION\"].dt.total_seconds()/60)*(df_temp[\"PATIENTWEIGHT\"])\n",
    "\n",
    "#Check with a 0.01 tolerance\n",
    "assert(len(df_temp.loc[(abs(df_temp[\"COMPUTED_AMOUNT\"]-1000*df_temp[\"AMOUNT\"])>0.01)].index)==0) #OK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "duration_split_hours=0.5\n",
    "to_sec_fact=3600*duration_split_hours\n",
    "\n",
    "#split data set in four.\n",
    "\n",
    "#The first dataframe contains the entries with no rate but with extended duration inputs (over 0.5 hour)\n",
    "df_temp1=inputs_small_3.loc[(inputs_small_3[\"DURATION\"]>timedelta(hours=duration_split_hours)) & (inputs_small_3[\"RATE\"].isnull())].copy().reset_index(drop=True)\n",
    "#The second dataframe contains the entries with no rate and low duration entries (<0.5hour)\n",
    "df_temp2=inputs_small_3.loc[(inputs_small_3[\"DURATION\"]<=timedelta(hours=duration_split_hours)) & (inputs_small_3[\"RATE\"].isnull())].copy().reset_index(drop=True)\n",
    "#The third dataframe contains the entries with a rate and extended duration inputs (over 0.5 hour)\n",
    "df_temp3=inputs_small_3.loc[(inputs_small_3[\"DURATION\"]>timedelta(hours=duration_split_hours)) & (inputs_small_3[\"RATE\"].notnull())].copy().reset_index(drop=True)\n",
    "#The forth dataframe contains the entries with a rate and low duration entries (< 0.5 hour)\n",
    "df_temp4=inputs_small_3.loc[(inputs_small_3[\"DURATION\"]<=timedelta(hours=duration_split_hours)) & (inputs_small_3[\"RATE\"].notnull())].copy().reset_index(drop=True)\n",
    "\n",
    "#Check if split is complete\n",
    "assert(len(df_temp1.index)+len(df_temp2.index)+len(df_temp3.index)+len(df_temp4.index)==len(inputs_small_3.index))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "#We then process all of these dfs.\n",
    "#In the first one, we need to duplicate the entries according to their duration and then divide each entry by the number of duplicates\n",
    "\n",
    "#We duplicate the rows with the number bins for each injection\n",
    "df_temp1[\"Repeat\"]=np.ceil(df_temp1[\"DURATION\"].dt.total_seconds()/to_sec_fact).astype(int)\n",
    "df_new1=df_temp1.reindex(df_temp1.index.repeat(df_temp1[\"Repeat\"]))\n",
    "#We then create the admninistration time as a shifted version of the STARTTIME.\n",
    "df_new1[\"CHARTTIME\"]=df_new1.groupby(level=0)['STARTTIME'].transform(lambda x: pd.date_range(start=x.iat[0],freq=str(60*duration_split_hours)+'min',periods=len(x)))\n",
    "#We divide each entry by the number of repeats\n",
    "df_new1[\"AMOUNT\"]=df_new1[\"AMOUNT\"]/df_new1[\"Repeat\"]\n",
    "\n",
    "\n",
    "# In the third one, we do the same\n",
    "#We duplicate the rows with the number bins for each injection\n",
    "df_temp3[\"Repeat\"]=np.ceil(df_temp3[\"DURATION\"].dt.total_seconds()/to_sec_fact).astype(int)\n",
    "df_new3=df_temp3.reindex(df_temp3.index.repeat(df_temp3[\"Repeat\"]))\n",
    "#We then create the admninistration time as a shifted version of the STARTTIME.\n",
    "df_new3[\"CHARTTIME\"]=df_new3.groupby(level=0)['STARTTIME'].transform(lambda x: pd.date_range(start=x.iat[0],freq=str(60*duration_split_hours)+'min',periods=len(x)))\n",
    "#We divide each entry by the number of repeats\n",
    "df_new3[\"AMOUNT\"]=df_new3[\"AMOUNT\"]/df_new3[\"Repeat\"]\n",
    "\n",
    "df_temp2[\"CHARTTIME\"]=df_temp2[\"STARTTIME\"]\n",
    "df_temp4[\"CHARTTIME\"]=df_temp4[\"STARTTIME\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Eventually, we merge all 4splits into one.\n",
    "inputs_small_4=df_new1.append([df_temp2,df_new3,df_temp4])\n",
    "#The result is a dataset with discrete inputs for each treatment."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LABEL</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albumin 5%</th>\n",
       "      <td>7984.0</td>\n",
       "      <td>196.469639</td>\n",
       "      <td>96.554213</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>124.999995</td>\n",
       "      <td>249.999990</td>\n",
       "      <td>249.999990</td>\n",
       "      <td>500.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Calcium Gluconate</th>\n",
       "      <td>27225.0</td>\n",
       "      <td>0.900840</td>\n",
       "      <td>0.302560</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>9.007998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D5 1/2NS</th>\n",
       "      <td>140735.0</td>\n",
       "      <td>37.272787</td>\n",
       "      <td>22.077725</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>37.037037</td>\n",
       "      <td>49.987469</td>\n",
       "      <td>1000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dextrose 5%</th>\n",
       "      <td>1280157.0</td>\n",
       "      <td>9.610933</td>\n",
       "      <td>16.706352</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.731343</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>9.172340</td>\n",
       "      <td>600.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furosemide (Lasix)</th>\n",
       "      <td>115479.0</td>\n",
       "      <td>6.727809</td>\n",
       "      <td>13.949675</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.955730</td>\n",
       "      <td>3.447752</td>\n",
       "      <td>7.135588</td>\n",
       "      <td>2320.000200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GT Flush</th>\n",
       "      <td>26003.0</td>\n",
       "      <td>49.500942</td>\n",
       "      <td>62.696443</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>50.000000</td>\n",
       "      <td>3750.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gastric Meds</th>\n",
       "      <td>38577.0</td>\n",
       "      <td>61.504676</td>\n",
       "      <td>94.879027</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>60.000000</td>\n",
       "      <td>4020.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heparin Sodium</th>\n",
       "      <td>234389.0</td>\n",
       "      <td>591.075743</td>\n",
       "      <td>424.007509</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>383.674861</td>\n",
       "      <td>531.222936</td>\n",
       "      <td>718.193882</td>\n",
       "      <td>30000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hydralazine</th>\n",
       "      <td>7308.0</td>\n",
       "      <td>11.751698</td>\n",
       "      <td>5.488737</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>160.000016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Glargine</th>\n",
       "      <td>4127.0</td>\n",
       "      <td>23.587109</td>\n",
       "      <td>28.025741</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>1515.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Humalog</th>\n",
       "      <td>12666.0</td>\n",
       "      <td>5.009016</td>\n",
       "      <td>4.512010</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>75.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Regular</th>\n",
       "      <td>240858.0</td>\n",
       "      <td>2.108631</td>\n",
       "      <td>2.969762</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.745380</td>\n",
       "      <td>1.478125</td>\n",
       "      <td>2.488362</td>\n",
       "      <td>810.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K Phos</th>\n",
       "      <td>32822.0</td>\n",
       "      <td>1.576087</td>\n",
       "      <td>0.786053</td>\n",
       "      <td>0.039982</td>\n",
       "      <td>1.153846</td>\n",
       "      <td>1.250000</td>\n",
       "      <td>2.194271</td>\n",
       "      <td>30.000001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KCL (Bolus)</th>\n",
       "      <td>43615.0</td>\n",
       "      <td>26.079884</td>\n",
       "      <td>7.297720</td>\n",
       "      <td>0.166667</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>50.000002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LR</th>\n",
       "      <td>258121.0</td>\n",
       "      <td>74.760064</td>\n",
       "      <td>169.190662</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>20.947510</td>\n",
       "      <td>45.952379</td>\n",
       "      <td>59.374999</td>\n",
       "      <td>23000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lorazepam (Ativan)</th>\n",
       "      <td>11009.0</td>\n",
       "      <td>1.243555</td>\n",
       "      <td>1.526588</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>120.000002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate</th>\n",
       "      <td>26450.0</td>\n",
       "      <td>1.007157</td>\n",
       "      <td>0.564905</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>24.999999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate (Bolus)</th>\n",
       "      <td>18249.0</td>\n",
       "      <td>25.080623</td>\n",
       "      <td>3.278394</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>60.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Metoprolol</th>\n",
       "      <td>15485.0</td>\n",
       "      <td>5.851928</td>\n",
       "      <td>4.017231</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>180.000018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Midazolam (Versed)</th>\n",
       "      <td>317183.0</td>\n",
       "      <td>1.893243</td>\n",
       "      <td>2.182632</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>1.000348</td>\n",
       "      <td>2.463700</td>\n",
       "      <td>80.000006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morphine Sulfate</th>\n",
       "      <td>37635.0</td>\n",
       "      <td>3.007026</td>\n",
       "      <td>10.389459</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.923077</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.998854</td>\n",
       "      <td>1945.000100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nitroglycerin</th>\n",
       "      <td>97661.0</td>\n",
       "      <td>2.537706</td>\n",
       "      <td>2.632051</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.836827</td>\n",
       "      <td>1.632653</td>\n",
       "      <td>3.404549</td>\n",
       "      <td>56.289019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Norepinephrine</th>\n",
       "      <td>216703.0</td>\n",
       "      <td>0.288203</td>\n",
       "      <td>0.361786</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.058424</td>\n",
       "      <td>0.158569</td>\n",
       "      <td>0.388953</td>\n",
       "      <td>15.881999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Cell Saver Intake</th>\n",
       "      <td>1509.0</td>\n",
       "      <td>611.918489</td>\n",
       "      <td>422.304142</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>700.000000</td>\n",
       "      <td>7500.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Crystalloid Intake</th>\n",
       "      <td>4312.0</td>\n",
       "      <td>2544.279917</td>\n",
       "      <td>1700.689937</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1400.000000</td>\n",
       "      <td>2500.000000</td>\n",
       "      <td>3200.000000</td>\n",
       "      <td>36000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PO Intake</th>\n",
       "      <td>63597.0</td>\n",
       "      <td>183.651965</td>\n",
       "      <td>940.150934</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>120.000000</td>\n",
       "      <td>240.000000</td>\n",
       "      <td>180120.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Packed Red Blood Cells</th>\n",
       "      <td>37744.0</td>\n",
       "      <td>90.097666</td>\n",
       "      <td>71.776546</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>46.874998</td>\n",
       "      <td>71.000002</td>\n",
       "      <td>138.999996</td>\n",
       "      <td>1404.999960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Phenylephrine</th>\n",
       "      <td>232594.0</td>\n",
       "      <td>2.349435</td>\n",
       "      <td>2.811417</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.659878</td>\n",
       "      <td>1.419048</td>\n",
       "      <td>2.952996</td>\n",
       "      <td>80.000006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Piggyback</th>\n",
       "      <td>46785.0</td>\n",
       "      <td>41.804094</td>\n",
       "      <td>29.979460</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>38.461540</td>\n",
       "      <td>49.999998</td>\n",
       "      <td>300.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Potassium Chloride</th>\n",
       "      <td>242714.0</td>\n",
       "      <td>3.146304</td>\n",
       "      <td>3.976212</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.738889</td>\n",
       "      <td>0.991700</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>500.000016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Solution</th>\n",
       "      <td>834404.0</td>\n",
       "      <td>6.208746</td>\n",
       "      <td>9.464254</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.984211</td>\n",
       "      <td>3.568866</td>\n",
       "      <td>9.081818</td>\n",
       "      <td>1600.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sterile Water</th>\n",
       "      <td>62860.0</td>\n",
       "      <td>13.477099</td>\n",
       "      <td>11.047709</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.600000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>14.285714</td>\n",
       "      <td>249.999990</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               count         mean          std       min  \\\n",
       "LABEL                                                                      \n",
       "Albumin 5%                    7984.0   196.469639    96.554213  0.000000   \n",
       "Calcium Gluconate            27225.0     0.900840     0.302560  0.000000   \n",
       "D5 1/2NS                    140735.0    37.272787    22.077725  0.000000   \n",
       "Dextrose 5%                1280157.0     9.610933    16.706352  0.000000   \n",
       "Furosemide (Lasix)          115479.0     6.727809    13.949675  0.000000   \n",
       "GT Flush                     26003.0    49.500942    62.696443  0.000000   \n",
       "Gastric Meds                 38577.0    61.504676    94.879027  0.000000   \n",
       "Heparin Sodium              234389.0   591.075743   424.007509  0.000000   \n",
       "Hydralazine                   7308.0    11.751698     5.488737  0.000000   \n",
       "Insulin - Glargine            4127.0    23.587109    28.025741  0.000000   \n",
       "Insulin - Humalog            12666.0     5.009016     4.512010  0.000000   \n",
       "Insulin - Regular           240858.0     2.108631     2.969762  0.000000   \n",
       "K Phos                       32822.0     1.576087     0.786053  0.039982   \n",
       "KCL (Bolus)                  43615.0    26.079884     7.297720  0.166667   \n",
       "LR                          258121.0    74.760064   169.190662  0.000000   \n",
       "Lorazepam (Ativan)           11009.0     1.243555     1.526588  0.000000   \n",
       "Magnesium Sulfate            26450.0     1.007157     0.564905  0.000000   \n",
       "Magnesium Sulfate (Bolus)    18249.0    25.080623     3.278394  0.833333   \n",
       "Metoprolol                   15485.0     5.851928     4.017231  0.000000   \n",
       "Midazolam (Versed)          317183.0     1.893243     2.182632  0.000000   \n",
       "Morphine Sulfate             37635.0     3.007026    10.389459  0.000000   \n",
       "Nitroglycerin                97661.0     2.537706     2.632051  0.000000   \n",
       "Norepinephrine              216703.0     0.288203     0.361786  0.000000   \n",
       "OR Cell Saver Intake          1509.0   611.918489   422.304142  0.000000   \n",
       "OR Crystalloid Intake         4312.0  2544.279917  1700.689937  0.000000   \n",
       "PO Intake                    63597.0   183.651965   940.150934  0.000000   \n",
       "Packed Red Blood Cells       37744.0    90.097666    71.776546  0.000000   \n",
       "Phenylephrine               232594.0     2.349435     2.811417  0.000000   \n",
       "Piggyback                    46785.0    41.804094    29.979460  0.000000   \n",
       "Potassium Chloride          242714.0     3.146304     3.976212  0.000000   \n",
       "Solution                    834404.0     6.208746     9.464254  0.000000   \n",
       "Sterile Water                62860.0    13.477099    11.047709  0.000000   \n",
       "\n",
       "                                   25%          50%          75%  \\\n",
       "LABEL                                                              \n",
       "Albumin 5%                  124.999995   249.999990   249.999990   \n",
       "Calcium Gluconate             1.000000     1.000000     1.000000   \n",
       "D5 1/2NS                     24.999999    37.037037    49.987469   \n",
       "Dextrose 5%                   3.731343     5.000000     9.172340   \n",
       "Furosemide (Lasix)            1.955730     3.447752     7.135588   \n",
       "GT Flush                     30.000000    30.000000    50.000000   \n",
       "Gastric Meds                 30.000000    40.000000    60.000000   \n",
       "Heparin Sodium              383.674861   531.222936   718.193882   \n",
       "Hydralazine                  10.000001    10.000001    10.000001   \n",
       "Insulin - Glargine           10.000000    20.000000    30.000000   \n",
       "Insulin - Humalog             2.000000     4.000000     6.000000   \n",
       "Insulin - Regular             0.745380     1.478125     2.488362   \n",
       "K Phos                        1.153846     1.250000     2.194271   \n",
       "KCL (Bolus)                  24.999999    24.999999    24.999999   \n",
       "LR                           20.947510    45.952379    59.374999   \n",
       "Lorazepam (Ativan)            0.500000     1.000000     2.000000   \n",
       "Magnesium Sulfate             1.000000     1.000000     1.000000   \n",
       "Magnesium Sulfate (Bolus)    24.999999    24.999999    24.999999   \n",
       "Metoprolol                    5.000000     5.000000     5.000000   \n",
       "Midazolam (Versed)            0.500000     1.000348     2.463700   \n",
       "Morphine Sulfate              1.923077     2.000000     3.998854   \n",
       "Nitroglycerin                 0.836827     1.632653     3.404549   \n",
       "Norepinephrine                0.058424     0.158569     0.388953   \n",
       "OR Cell Saver Intake        500.000000   500.000000   700.000000   \n",
       "OR Crystalloid Intake      1400.000000  2500.000000  3200.000000   \n",
       "PO Intake                   100.000000   120.000000   240.000000   \n",
       "Packed Red Blood Cells       46.874998    71.000002   138.999996   \n",
       "Phenylephrine                 0.659878     1.419048     2.952996   \n",
       "Piggyback                    24.999999    38.461540    49.999998   \n",
       "Potassium Chloride            0.738889     0.991700     5.000000   \n",
       "Solution                      0.984211     3.568866     9.081818   \n",
       "Sterile Water                 9.600000    10.000000    14.285714   \n",
       "\n",
       "                                     max  \n",
       "LABEL                                     \n",
       "Albumin 5%                    500.000000  \n",
       "Calcium Gluconate               9.007998  \n",
       "D5 1/2NS                     1000.000000  \n",
       "Dextrose 5%                   600.000000  \n",
       "Furosemide (Lasix)           2320.000200  \n",
       "GT Flush                     3750.000000  \n",
       "Gastric Meds                 4020.000000  \n",
       "Heparin Sodium              30000.000000  \n",
       "Hydralazine                   160.000016  \n",
       "Insulin - Glargine           1515.000000  \n",
       "Insulin - Humalog              75.000000  \n",
       "Insulin - Regular             810.000000  \n",
       "K Phos                         30.000001  \n",
       "KCL (Bolus)                    50.000002  \n",
       "LR                          23000.000000  \n",
       "Lorazepam (Ativan)            120.000002  \n",
       "Magnesium Sulfate              24.999999  \n",
       "Magnesium Sulfate (Bolus)      60.000000  \n",
       "Metoprolol                    180.000018  \n",
       "Midazolam (Versed)             80.000006  \n",
       "Morphine Sulfate             1945.000100  \n",
       "Nitroglycerin                  56.289019  \n",
       "Norepinephrine                 15.881999  \n",
       "OR Cell Saver Intake         7500.000000  \n",
       "OR Crystalloid Intake       36000.000000  \n",
       "PO Intake                  180120.000000  \n",
       "Packed Red Blood Cells       1404.999960  \n",
       "Phenylephrine                  80.000006  \n",
       "Piggyback                     300.000000  \n",
       "Potassium Chloride            500.000016  \n",
       "Solution                     1600.000000  \n",
       "Sterile Water                 249.999990  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs_small_4.groupby(\"LABEL\")[\"AMOUNT\"].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Again, we remove all the observations that are more than 5std away from the mean.\n",
    "\n",
    "amount_desc=inputs_small_4.groupby(\"LABEL\")[\"AMOUNT\"].describe()\n",
    "name_list=list(amount_desc.loc[amount_desc[\"count\"]!=0].index)\n",
    "for label in name_list:\n",
    "    inputs_small_4=inputs_small_4.drop(inputs_small_4.loc[(inputs_small_4[\"LABEL\"]==label)&(inputs_small_4[\"AMOUNT\"]>(amount_desc.loc[label,\"mean\"]+5*amount_desc.loc[label,\"std\"]))].index).copy()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LABEL</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albumin 5%</th>\n",
       "      <td>7983.0</td>\n",
       "      <td>196.431616</td>\n",
       "      <td>96.500468</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>124.999995</td>\n",
       "      <td>249.999990</td>\n",
       "      <td>249.999990</td>\n",
       "      <td>500.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Calcium Gluconate</th>\n",
       "      <td>26163.0</td>\n",
       "      <td>0.898323</td>\n",
       "      <td>0.297023</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D5 1/2NS</th>\n",
       "      <td>140224.0</td>\n",
       "      <td>37.062061</td>\n",
       "      <td>20.332373</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>37.037037</td>\n",
       "      <td>49.978560</td>\n",
       "      <td>142.857146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dextrose 5%</th>\n",
       "      <td>1160685.0</td>\n",
       "      <td>8.721031</td>\n",
       "      <td>11.162632</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.728571</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>8.852611</td>\n",
       "      <td>93.055552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furosemide (Lasix)</th>\n",
       "      <td>113409.0</td>\n",
       "      <td>5.945197</td>\n",
       "      <td>7.741557</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.949558</td>\n",
       "      <td>3.423073</td>\n",
       "      <td>7.050000</td>\n",
       "      <td>60.000002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GT Flush</th>\n",
       "      <td>25116.0</td>\n",
       "      <td>47.749841</td>\n",
       "      <td>48.647136</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>50.000000</td>\n",
       "      <td>360.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gastric Meds</th>\n",
       "      <td>36997.0</td>\n",
       "      <td>56.947953</td>\n",
       "      <td>50.897849</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>60.000000</td>\n",
       "      <td>520.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heparin Sodium</th>\n",
       "      <td>233273.0</td>\n",
       "      <td>577.439340</td>\n",
       "      <td>326.936976</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>383.111102</td>\n",
       "      <td>529.421989</td>\n",
       "      <td>714.285748</td>\n",
       "      <td>2704.062477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hydralazine</th>\n",
       "      <td>7234.0</td>\n",
       "      <td>11.560189</td>\n",
       "      <td>4.417902</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>10.000001</td>\n",
       "      <td>30.000001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Glargine</th>\n",
       "      <td>4116.0</td>\n",
       "      <td>23.194849</td>\n",
       "      <td>15.511370</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>150.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Humalog</th>\n",
       "      <td>12601.0</td>\n",
       "      <td>4.839632</td>\n",
       "      <td>3.788863</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>27.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Insulin - Regular</th>\n",
       "      <td>230429.0</td>\n",
       "      <td>2.062932</td>\n",
       "      <td>2.084401</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.747425</td>\n",
       "      <td>1.480000</td>\n",
       "      <td>2.488392</td>\n",
       "      <td>16.765808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K Phos</th>\n",
       "      <td>27503.0</td>\n",
       "      <td>1.554467</td>\n",
       "      <td>0.583514</td>\n",
       "      <td>0.039982</td>\n",
       "      <td>1.153846</td>\n",
       "      <td>1.250000</td>\n",
       "      <td>2.142857</td>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KCL (Bolus)</th>\n",
       "      <td>43614.0</td>\n",
       "      <td>26.080463</td>\n",
       "      <td>7.296802</td>\n",
       "      <td>0.166667</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>50.000002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LR</th>\n",
       "      <td>248477.0</td>\n",
       "      <td>55.667621</td>\n",
       "      <td>87.683459</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>19.612904</td>\n",
       "      <td>43.278898</td>\n",
       "      <td>57.812499</td>\n",
       "      <td>900.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lorazepam (Ativan)</th>\n",
       "      <td>10963.0</td>\n",
       "      <td>1.215187</td>\n",
       "      <td>0.889103</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>8.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate</th>\n",
       "      <td>25804.0</td>\n",
       "      <td>0.991435</td>\n",
       "      <td>0.215328</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Magnesium Sulfate (Bolus)</th>\n",
       "      <td>18041.0</td>\n",
       "      <td>24.795381</td>\n",
       "      <td>1.893760</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>34.999998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Metoprolol</th>\n",
       "      <td>15348.0</td>\n",
       "      <td>5.765853</td>\n",
       "      <td>2.920962</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>25.000002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Midazolam (Versed)</th>\n",
       "      <td>314614.0</td>\n",
       "      <td>1.830940</td>\n",
       "      <td>1.841343</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>1.000183</td>\n",
       "      <td>2.458013</td>\n",
       "      <td>12.675620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morphine Sulfate</th>\n",
       "      <td>37545.0</td>\n",
       "      <td>2.954195</td>\n",
       "      <td>2.750287</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.931432</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.998854</td>\n",
       "      <td>50.000001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nitroglycerin</th>\n",
       "      <td>97256.0</td>\n",
       "      <td>2.481253</td>\n",
       "      <td>2.410982</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.835280</td>\n",
       "      <td>1.621888</td>\n",
       "      <td>3.377449</td>\n",
       "      <td>15.571214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Norepinephrine</th>\n",
       "      <td>198326.0</td>\n",
       "      <td>0.306612</td>\n",
       "      <td>0.335205</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.076169</td>\n",
       "      <td>0.180153</td>\n",
       "      <td>0.420034</td>\n",
       "      <td>2.094934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Cell Saver Intake</th>\n",
       "      <td>1497.0</td>\n",
       "      <td>585.732131</td>\n",
       "      <td>244.863243</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>700.000000</td>\n",
       "      <td>2500.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OR Crystalloid Intake</th>\n",
       "      <td>4302.0</td>\n",
       "      <td>2513.873780</td>\n",
       "      <td>1545.291486</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1400.000000</td>\n",
       "      <td>2500.000000</td>\n",
       "      <td>3200.000000</td>\n",
       "      <td>11000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PO Intake</th>\n",
       "      <td>63526.0</td>\n",
       "      <td>178.123194</td>\n",
       "      <td>134.276296</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>120.000000</td>\n",
       "      <td>240.000000</td>\n",
       "      <td>4800.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Packed Red Blood Cells</th>\n",
       "      <td>37626.0</td>\n",
       "      <td>89.261181</td>\n",
       "      <td>68.770809</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>46.874998</td>\n",
       "      <td>70.999997</td>\n",
       "      <td>138.999993</td>\n",
       "      <td>384.999990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Phenylephrine</th>\n",
       "      <td>231526.0</td>\n",
       "      <td>2.280101</td>\n",
       "      <td>2.502026</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.659341</td>\n",
       "      <td>1.411043</td>\n",
       "      <td>2.926213</td>\n",
       "      <td>16.390244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Piggyback</th>\n",
       "      <td>46341.0</td>\n",
       "      <td>40.123155</td>\n",
       "      <td>23.796789</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>24.999999</td>\n",
       "      <td>38.461540</td>\n",
       "      <td>49.999998</td>\n",
       "      <td>187.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Potassium Chloride</th>\n",
       "      <td>232492.0</td>\n",
       "      <td>3.133674</td>\n",
       "      <td>3.798524</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.738889</td>\n",
       "      <td>0.991700</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>20.000001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Solution</th>\n",
       "      <td>827438.0</td>\n",
       "      <td>6.144743</td>\n",
       "      <td>7.569991</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.985477</td>\n",
       "      <td>3.580815</td>\n",
       "      <td>9.090909</td>\n",
       "      <td>53.333330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sterile Water</th>\n",
       "      <td>60103.0</td>\n",
       "      <td>12.970725</td>\n",
       "      <td>8.134143</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.572072</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>14.285714</td>\n",
       "      <td>66.699996</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               count         mean          std       min  \\\n",
       "LABEL                                                                      \n",
       "Albumin 5%                    7983.0   196.431616    96.500468  0.000000   \n",
       "Calcium Gluconate            26163.0     0.898323     0.297023  0.000000   \n",
       "D5 1/2NS                    140224.0    37.062061    20.332373  0.000000   \n",
       "Dextrose 5%                1160685.0     8.721031    11.162632  0.000000   \n",
       "Furosemide (Lasix)          113409.0     5.945197     7.741557  0.000000   \n",
       "GT Flush                     25116.0    47.749841    48.647136  0.000000   \n",
       "Gastric Meds                 36997.0    56.947953    50.897849  0.000000   \n",
       "Heparin Sodium              233273.0   577.439340   326.936976  0.000000   \n",
       "Hydralazine                   7234.0    11.560189     4.417902  0.000000   \n",
       "Insulin - Glargine            4116.0    23.194849    15.511370  0.000000   \n",
       "Insulin - Humalog            12601.0     4.839632     3.788863  0.000000   \n",
       "Insulin - Regular           230429.0     2.062932     2.084401  0.000000   \n",
       "K Phos                       27503.0     1.554467     0.583514  0.039982   \n",
       "KCL (Bolus)                  43614.0    26.080463     7.296802  0.166667   \n",
       "LR                          248477.0    55.667621    87.683459  0.000000   \n",
       "Lorazepam (Ativan)           10963.0     1.215187     0.889103  0.000000   \n",
       "Magnesium Sulfate            25804.0     0.991435     0.215328  0.000000   \n",
       "Magnesium Sulfate (Bolus)    18041.0    24.795381     1.893760  0.833333   \n",
       "Metoprolol                   15348.0     5.765853     2.920962  0.000000   \n",
       "Midazolam (Versed)          314614.0     1.830940     1.841343  0.000000   \n",
       "Morphine Sulfate             37545.0     2.954195     2.750287  0.000000   \n",
       "Nitroglycerin                97256.0     2.481253     2.410982  0.000000   \n",
       "Norepinephrine              198326.0     0.306612     0.335205  0.000000   \n",
       "OR Cell Saver Intake          1497.0   585.732131   244.863243  0.000000   \n",
       "OR Crystalloid Intake         4302.0  2513.873780  1545.291486  0.000000   \n",
       "PO Intake                    63526.0   178.123194   134.276296  0.000000   \n",
       "Packed Red Blood Cells       37626.0    89.261181    68.770809  0.000000   \n",
       "Phenylephrine               231526.0     2.280101     2.502026  0.000000   \n",
       "Piggyback                    46341.0    40.123155    23.796789  0.000000   \n",
       "Potassium Chloride          232492.0     3.133674     3.798524  0.000000   \n",
       "Solution                    827438.0     6.144743     7.569991  0.000000   \n",
       "Sterile Water                60103.0    12.970725     8.134143  0.000000   \n",
       "\n",
       "                                   25%          50%          75%           max  \n",
       "LABEL                                                                           \n",
       "Albumin 5%                  124.999995   249.999990   249.999990    500.000000  \n",
       "Calcium Gluconate             1.000000     1.000000     1.000000      2.000000  \n",
       "D5 1/2NS                     24.999999    37.037037    49.978560    142.857146  \n",
       "Dextrose 5%                   3.728571     5.000000     8.852611     93.055552  \n",
       "Furosemide (Lasix)            1.949558     3.423073     7.050000     60.000002  \n",
       "GT Flush                     30.000000    30.000000    50.000000    360.000000  \n",
       "Gastric Meds                 30.000000    40.000000    60.000000    520.000000  \n",
       "Heparin Sodium              383.111102   529.421989   714.285748   2704.062477  \n",
       "Hydralazine                  10.000001    10.000001    10.000001     30.000001  \n",
       "Insulin - Glargine           10.000000    20.000000    30.000000    150.000000  \n",
       "Insulin - Humalog             2.000000     4.000000     6.000000     27.000000  \n",
       "Insulin - Regular             0.747425     1.480000     2.488392     16.765808  \n",
       "K Phos                        1.153846     1.250000     2.142857      5.000000  \n",
       "KCL (Bolus)                  24.999999    24.999999    24.999999     50.000002  \n",
       "LR                           19.612904    43.278898    57.812499    900.000000  \n",
       "Lorazepam (Ativan)            0.500000     1.000000     2.000000      8.000000  \n",
       "Magnesium Sulfate             1.000000     1.000000     1.000000      2.500000  \n",
       "Magnesium Sulfate (Bolus)    24.999999    24.999999    24.999999     34.999998  \n",
       "Metoprolol                    5.000000     5.000000     5.000000     25.000002  \n",
       "Midazolam (Versed)            0.500000     1.000183     2.458013     12.675620  \n",
       "Morphine Sulfate              1.931432     2.000000     3.998854     50.000001  \n",
       "Nitroglycerin                 0.835280     1.621888     3.377449     15.571214  \n",
       "Norepinephrine                0.076169     0.180153     0.420034      2.094934  \n",
       "OR Cell Saver Intake        500.000000   500.000000   700.000000   2500.000000  \n",
       "OR Crystalloid Intake      1400.000000  2500.000000  3200.000000  11000.000000  \n",
       "PO Intake                   100.000000   120.000000   240.000000   4800.000000  \n",
       "Packed Red Blood Cells       46.874998    70.999997   138.999993    384.999990  \n",
       "Phenylephrine                 0.659341     1.411043     2.926213     16.390244  \n",
       "Piggyback                    24.999999    38.461540    49.999998    187.500000  \n",
       "Potassium Chloride            0.738889     0.991700     5.000000     20.000001  \n",
       "Solution                      0.985477     3.580815     9.090909     53.333330  \n",
       "Sterile Water                 9.572072    10.000000    14.285714     66.699996  "
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs_small_4.groupby(\"LABEL\")[\"AMOUNT\"].describe()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "inputs_small_4.to_csv(file_path+\"INPUTS_processed.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.06449676136363636"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(inputs_small_4.index)/(22000*32*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10100"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs_small[\"HADM_ID\"].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
